样例给的有问题吧?

P1906 凯撒密码

抱歉,样例无问题,程序出了一小点问题
by yfct @ 2018-02-22 07:23:34


非常抱歉
by yfct @ 2018-02-22 07:23:45


重申一遍,凯撒密码这道题的样例第二句话有问题,“N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ”中,N出现了8次,而样例中翻译后为E的字母J只出现了7次,所以N应为密码,数据有误! @[kkksc03](/space/show?uid=1) @[chen_zhe](/space/show?uid=8457) @[icy](/space/show?uid=20487)
by yfct @ 2018-02-22 07:32:40


您最好一次只@一个管理
by qqvq @ 2018-02-22 07:37:06


@[Ycrpro](/space/show?uid=29089) 谢谢
by yfct @ 2018-02-22 07:44:31


```C++ #include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring> #include <string> using namespace std; void work(string a){ if(a=="START") return ; if(a=="END") return ; //' ':32 //',':44 long long len=a.length(); int cnt[300]; memset(cnt,0,sizeof(cnt)); for(int i=0;i<len;i++){ if(a[i]==' ' || a[i]==',') continue; else{ cnt[int(a[i])]++; } } //Code here to guess the password... //maxn: 出现最多的字符的ascii码值 //tot: 出现最多的字符出现的个数 int maxn=-1,tot=-1; for(int i=65;i<=90;i++){ if(cnt[i]>=tot) tot=cnt[i],maxn=i; } for(int i=97;i<=122;i++){ if(cnt[i]>=tot) tot=cnt[i],maxn=i; } //cout<<maxn<<endl<<tot<<endl; int password=maxn-'E'; //cout<<password<<endl; for(int i=0;i<len;i++){ if(a[i]==' ' || a[i]==',') printf("%c",a[i]); else printf("%c",a[i]-password<65?a[i]-password+26:a[i]-password); } printf("\n"); } string s; int main(){ while(getline(cin,s) && s!="ENDOFINPUT"){ work(s); } return 0; } ``` 您好,这是我的代码,请您指正!谢谢!
by yfct @ 2018-02-22 07:45:22


```C++ #include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring> #include <string> using namespace std; void work(string a){ if(a=="START") return ; if(a=="END") return ; //' ':32 //',':44 long long len=a.length(); int cnt[300]; memset(cnt,0,sizeof(cnt)); for(int i=0;i<len;i++){ if(a[i]==' ' || a[i]==',') continue; else{ cnt[int(a[i])]++; } } //Code here to guess the password... //maxn: 出现最多的字符的ascii码值 //tot: 出现最多的字符出现的个数 int maxn=-1,tot=-1; for(int i=65;i<=90;i++){ if(cnt[i]>=tot) tot=cnt[i],maxn=i; } for(int i=97;i<=122;i++){ if(cnt[i]>=tot) tot=cnt[i],maxn=i; } //cout<<maxn<<endl<<tot<<endl; int password=maxn-'E'; //cout<<password<<endl; for(int i=0;i<len;i++){ if(a[i]==' ' || a[i]==',') printf("%c",a[i]); else printf("%c",a[i]-password<65?a[i]-password+26:a[i]-password); } printf("\n"); } string s; int main(){ while(getline(cin,s) && s!="ENDOFINPUT"){ work(s); } return 0; } ``` 您好,这是我的代码,请您指正,谢谢!
by yfct @ 2018-02-22 07:46:11


```cpp #include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring> #include <string> using namespace std; void work(string a){ if(a=="START") return ; if(a=="END") return ; //' ':32 //',':44 long long len=a.length(); int cnt[300]; memset(cnt,0,sizeof(cnt)); for(int i=0;i<len;i++){ if(a[i]==' ' || a[i]==',') continue; else{ cnt[int(a[i])]++; } } //Code here to guess the password... //maxn: 出现最多的字符的ascii码值 //tot: 出现最多的字符出现的个数 int maxn=-1,tot=-1; for(int i=65;i<=90;i++){ if(cnt[i]>=tot) tot=cnt[i],maxn=i; } for(int i=97;i<=122;i++){ if(cnt[i]>=tot) tot=cnt[i],maxn=i; } //cout<<maxn<<endl<<tot<<endl; int password=maxn-'E'; //cout<<password<<endl; for(int i=0;i<len;i++){ if(a[i]==' ' || a[i]==',') printf("%c",a[i]); else printf("%c",a[i]-password<65?a[i]-password+26:a[i]-password); } printf("\n"); } string s; int main(){ while(getline(cin,s) && s!="ENDOFINPUT"){ work(s); } return 0; } ```
by yfct @ 2018-02-22 07:46:39


确实是这样
by MyukiyoMekya @ 2018-10-17 21:48:13


|