2018年1月13日 星期六

UVA Q10008 - What's Cryptanalysis

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<ctype.h>
using namespace std;
int main(){
int a,c[26],l,lp;
cin>>a;
char b[2000],d;
memset (c,0,sizeof(c));
for(int x=0;x<=a;x++){
    gets(b);
    for(int y=0;y<strlen(b);y++){
        if(isalpha(b[y])){
            if(b[y]-65>25){
                b[y]=b[y]-32;
            }
            cout<<b[y]-65<<" ";
            c[b[y]-65]++;
        }
    }
}
while(1){
    l=0;
    lp=0;
    for(int y=0;y<26;y++){
        if(c[y]>l){
            l=c[y];
            lp=y;
        }
    }
    if(l==0){
        break;
    }
    d=lp+65;
    cout<<d<<" "<<l<<endl;
    c[lp]=0;
}

system("pause");
return 0;
}

沒有留言:

張貼留言