您的位置:首页 > 其它

Runtime error 可能是scanf函数出现问题 poj3630

2014-11-24 18:50 260 查看
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

const int MAX=10010;
int main()
{
string str[MAX];
int test;
scanf("%d",&test);
while(test--){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
<strong>scanf("%s",str[i]);</strong>

sort(str+0,str+n);
bool flag=true;
for(int i=0;i<n-1;i++)
{
int len=str[i].length();
string tmp=str[i+1].substr(0,len);
if(str[i]==tmp)
{
flag=false;
break;
}
}
if(flag) printf("%s\n","YES");
else
printf("%s\n","NO");
}
}
这是POJ3630的源代码,但是一直是runtime error ,逻辑没有问题。后来把 scanf("%s",str[i])改为 cin>>str[i];才AC;但至今还没办法理解,为什么用scanf()会出错。经验:以后OJ上是runtime error,如果确实找不到原因,可以尝试把scanf()改用cin

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: