P1906 凯撒密码 求助
  • 板块学术版
  • 楼主Graygoo
  • 当前回复0
  • 已保存回复0
  • 发布时间2021/9/21 11:07
  • 上次更新2023/11/4 05:59:17
查看原帖
P1906 凯撒密码 求助
535714
Graygoo楼主2021/9/21 11:07
#include<bits/stdc++.h>
using namespace std;
string Big(string ori)//转大写
{
	for (int i=0;i<ori.length();i++){
		if ('a'<=ori[i] && ori[i]<='z'){
			ori[i]-=32;
		}
	}
	return ori;
 } 
string Trans(string ori,int t){
	string ans;
	for (int i=0;i<ori.length();i++){
		if ('a'<=ori[i] && ori[i]<='z'){
			if (ori[i]-'a'+1>=t)ans+=ori[i]-t+1;
			else ans+='z'-t+(ori[i]-'a')+2;
		}
		else if ('A'<=ori[i] && ori[i]<='Z'){
			if (ori[i]-'A'+1>=t)ans+=ori[i]-t+1;
			else ans+='Z'-t+(ori[i]-'A')+2;
		}
		else ans+=ori[i];
	}
	return ans;
}
int main(){
	int Poss[27];string m[10001]; 
     string tmp;
     while(cin>>tmp){
     	if (tmp=="ENDOFINPUT")return 0;
     	if (tmp=="START"){
     		cin>>m[1];
     		int ptr=1;
     		while(m[ptr]!="END"){
              cin>>m[++ptr];
              if (m[ptr]=="END")continue;
              for (int j=0;j<m[ptr].length();j++){
              	if ('a'<=m[ptr][j] && m[ptr][j]<='z')Poss[m[ptr][j]-'a']++;
              	else if ('A'<=m[ptr][j] && m[ptr][j]<='Z')Poss[m[ptr][j]-'A']++;
              }
			 }
			 int maxxx=-1,maxx;
			 for (int j=0;j<26;j++){
			 	if (Poss[j]>=maxxx)maxxx=Poss[j],maxx=j;
			 }
			 //cout<<maxx<<" "<<ptr;
			 for (int j=1;j<ptr;j++)cout<<Big(Trans(m[j],maxx-3))<<" ";
			 cout<<endl;
			 //for (int j=0;j<26;j++)Poss[j]=0;
		 }
	 }
} 
2021/9/21 11:07
加载中...