3 条题解
-
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
- 标签
- 递交数
- 62
- 已通过
- 22
- 上传者