CENCRY
如 spoj 中所述的问题,这是我的源代码,我的源代码的顺序为 O(strlen),但仍然给出超过时间限制,逻辑上有任何帮助。
int main()
{
int T,pos,loc;
cin>>T;
char str[50000], vowel[]= {"aeiou"}, consonant[] = {"bcdfghjklmnpqrstvwxyz"};
int hash[26]={0,0,1,2,1,3,4,5,2,6,7,8,9,10,3,11,12,13,14,15,4,16,17,18,19,20};
while(T--)
{
int hashC[26]={0};
cin >> str;
for(int i = 0;i < strlen(str); i++)
{
int ch=str[i]-97;
pos = hash[ch];
loc = hashC[ch];
switch(ch)
{
case 0:
case 4:
case 8:
case 14:
case 20:
cout<<consonant[(loc*5+pos)%21];
break;
default:
cout<<vowel[(loc*21+pos)%5];
break;
}
hashC[ch]++;
}
cout<<endl;
}
}
尝试使用 scanf 和 printf 而不是使用 std::cin 和 std::cout - 这些函数可能会使您的编程速度更快,特别是当在 stdin 上给出大量数据时。除了...您应该使用 srlen ONCE 并将输出写入某个变量,然后在“for”循环中使用它。
顺便说一句。你应该给我们链接到你的任务,因为你的算法可能根本就错了,即使我以前的建议也不足以解决你的问题。
我是一名优秀的程序员,十分优秀!