4 条题解

  • 2
    @ 2026-6-5 15:27:07
    #include<string> 
    using namespace std;
    int main(){
    	freopen("cnt.in", "r", stdin);
            freopen("cnt.out", "w", stdout);
    	int a[26]={0};
    	string n;
    	cin>>n;
    	for(int i=0;i<n.size();i++){
    		a[n[i]-97]++;
    	}
    	for(int i=0;i<26;i++){
    		cout<<a[i]<<" ";
    	}
    	return 0;
    }****
    
    
    • 0
      @ 2026-10-7 18:50:49
      常规写法
      #include <bits/stdc++.h> 
      using namespace std ; 
      
      int main() {
          freopen("cnt.in", "r", stdin);
          freopen("cnt.out", "w", stdout);
          ios::sync_with_stdio(false);
          cin.tie(nullptr);
           
          long long a[ 125 ] = {  } ; 
          string s ; 
          cin >> s ; 
          for ( int i = 0 ; i <= s.size(  ) - 1 ; i ++ )
          {
              a[ s[ i ] ] ++ ; 
          }
      
          for ( int i = 'a' ; i <= 'z' ; i ++ )
          {
              cout << a[ i ] << " " ; 
          }
      
          return 0;
      }
      
      
      • 0
        @ 2026-7-13 14:47:33

        用getchar()边读边算,节省内存。

        #include <cstdio>
        using namespace std;
        int main() {
            freopen("cnt.in", "r", stdin);
            freopen("cnt.out", "w", stdout);
        
            int ch;
            int letter[27] = {0};
            while ((ch = getchar()) != EOF) {
                letter[ch - 96]++;
            }
            for (int i = 1; i < 27; i++) {
                printf("%d ",letter[i]);
            }
          return 0;
        }
        
        
        
        • -1
          @ 2026-6-12 10:57:23

          #include #include using namespace std;

          int main(){ freopen("cnt.in", "r", stdin); freopen("cnt.out", "w", stdout); string specialChar="abcdefghijklmnopqrstuvwxyz"; int cnt[26]={0}; string S; getline(cin, S); size_t i; for(i=0;i<S.length();i++){ size_t pos=specialChar.find(S[i]); if(pos!=string::npos){ cnt[pos]++; } } for(int i=0;i<26;i++){ cout<<cnt[i]<<" "; } return 0; }

          • 1

          信息

          ID
          150
          时间
          1000ms
          内存
          256MiB
          难度
          1
          标签
          递交数
          67
          已通过
          24
          上传者