社区讨论
迷之TLE???
P1906凯撒密码参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi7x4nmf
- 此快照首次捕获于
- 2025/11/21 05:03 4 个月前
- 此快照最后确认于
- 2025/11/21 05:03 4 个月前
有大佬帮我看看么?本地和在线IDE给结果都是挺快的,提交上去就是4个TLE和1个WA
CPP#include<iostream>
#include<cstdio>
using namespace std;
struct Node{
int num;
char ch;
} maxx;
string str;
bool st,fi;
int t,num[26];
inline void BIG(string &str)
{
for(unsigned int i=0;i<str.size();++i)
if('a'<=str[i]&&str[i]<='z')
str[i]-=32;
}
int main(int argc, char const *argv[])
{
// freopen("in.txt","r",stdin);
while (true)
{
getline(cin,str);
if (!st&&str=="START")
{
st=true;
continue;
}
if (st&&str=="END")
{
st=false;
continue;
}
if (!st&&str=="ENDOFINPUT") break;
if (st)
{
BIG(str);
if (!fi)
{
for (unsigned int i=0; i<str.size(); ++i)
if ('A'<=str[i]&&str[i]<='Z')
if (++num[str[i]-'A']>=maxx.num)
maxx.num=num[str[i]-'A'],maxx.ch=str[i];
t=maxx.ch-'E';
fi=true;
}
for (unsigned int i=0; i<str.size(); ++i)
if ('A'>str[i]||str[i]>'Z')
printf("%c",str[i]);
else if ('A'<=str[i]&&str[i]<='Z')
printf("%c",str[i]-t<'A'?str[i]-t+26:str[i]-t);
printf("\n");
}
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...