4 条题解
-
0
常规写法 #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
用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
#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
- 上传者