#44436: cpe若過不了是數字後面有空格


chentuyi1210@gmail.com (CPE zero how to lose)

學校 : 不指定學校
編號 : 228574
來源 : [60.249.201.206]
最後登入時間 :
2025-03-25 11:16:51
c044. 10008 - What's Cryptanalysis -- UVa10008 | From: [39.1.12.237] | 發表日期 : 2024-12-05 02:51

#include<bits/stdc++.h>
/*
計算全部字串裡個個字母出現的多寡 
*/
/*
輸出流會有白癡問題 要在讀取完字串後接 cout.flush(); (好像可以不用) ,腦逼邊義氣真的有腦幹問題 
要處理第一個數字輸入後會有空白緊接在後 用 cin.peak()來看是否可開始讀取字串 或是要繼續ignore
 
*/
using namespace std;
 
int main(){
int line, len=0;
cin >> line;
int count[26]={0};
cin.ignore();
 
// peak 偷窺
while (cin.peek() == ' ' || cin.peek() == '\n') { // 糙你嗎,不用這個就不會過 
        //cin.get();
        cin.ignore();
    }
 
while(line>0){
char str[10000];
cin.getline(str, 1000, '\n');
for(int i=0;str[i]!='\0'; i++){
if( isalpha(str[i]) ){
 
str[i] = toupper(str[i]);
count[ str[i]-'A' ]++;
}
 
}
line--;
//cout.flush(); 可有可無 
}
 
//可有可無
int max_fre = 0;
for(int i=0;i<26;i++){
if(count[i]>max_fre) max_fre=count[i];
}//cout << max_fre<<endl;
 
for(int i=max_fre;i>=1;i--){
for(int k=0;k<26;k++){
if(count[k] == i){
cout << (char)(k+'A') << " "<<count[k]<<endl; 
}
}
}
 
return 0;
}
 
ZeroJudge Forum