3 条题解

  • 2
    @ 2024-2-8 13:17:10

    来啦!C++AC代码

    #include <iostream>
    #include <string> 
    using namespace std; 
    int main(){ 
        string a; 
        getline(cin, a); 
        a = ' ' + a; 
        a[a.size() - 1] = ' '; 
        a += '.'; int loc = 0; 
        int num = 0; 
        int max_loc = 0; int max_num = 0; 
        int i; 
        if (a.find('a') > a.size()){ 
            cout << "NO";
        } 
        else{ 
            for (i = 0; i < a.size(); i++){ 
                for (i; i < a.size(); i++){ 
                    if (a[i] == 'a') 
                        break;  
                } 
                for (i; i >= 0; i--){ 
                    if (a[i] == ' '){ 
                        loc = i + 1; 
                        break; 
                    } 
                } 
                for (i = i + 1; i < a.size(); i++){ 
                    if (a[i] != ' ') 
                        num++;  
                    else{ 
                        if (max_num < num){ 
                            max_num = num; 
                            max_loc = loc;
                        } 
                        num = 0; 
                        break;
                    } 
                } 
            } 
            for (int i = max_loc; i < max_loc + max_num; i++)
                cout << a[i];  
            return 0; 
        } 
    }
    

    帮hetao12726604格式化一下~

    • 1
      @ 2023-8-20 21:36:39

      c++不会,只能摸鱼了👀️ python3 AC代码

      a = input()
      mw = ''
      mws = 0
      t = ''
      ts = 0
      s = 0
      b = a.split()
      for i in b:
          if ("a" not in i):
              s += 1;
      for i in a:
          if s == len(b):
              break
          if i != ' ' and i != '.':
              t += i
              ts += 1
          else:
              if ts > mws and "a" in t:
                  mws = ts
                  mw = t
              t = ''
              ts = 0
      if s == len(b):
          print("NO")
      else:
          print(mw)
      
      • 1
        @ 2023-7-8 10:02:35

        #include <iostream> #include <string> using namespace std; int main() { string a; getline(cin, a); a = ' ' + a;//在string前面加个空格好识别 a[a.size() - 1] = ' '; a += '.'; int loc = 0; int num = 0;//记录单词的字母个数 int max_loc = 0; int max_num = 0; int i; if (a.find('a') > a.size()) { cout << "NO";//没有a直接NO掉就可以了,find函数如果没有找到的话会返回一个超大的值 return 0; } else { for (i = 0; i < a.size(); i++) { for (i; i < a.size(); i++) { if (a[i] == 'a') { break; } } for (i; i >= 0; i--) { if (a[i] == ' ') { loc = i + 1; break; } } for (i = i + 1; i < a.size(); i++) { if (a[i] != ' ') { num++; } else { if (max_num < num) { max_num = num; max_loc = loc; } num = 0; break; } } } for (int i = max_loc; i < max_loc + max_num; i++) { cout << a[i]; } return 0; } }

        • 1

        信息

        ID
        111
        时间
        1000ms
        内存
        16MiB
        难度
        2
        标签
        递交数
        77
        已通过
        45
        上传者