The last case is followed by a line containing one zero.
For each test case, if there exits a phone number that cannot be called, print “NO”, otherwise print “YES” instead.
0
YES
字符串两两比较,判断一个串是否为另一个串的前缀。。
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int cmpstr(string a,string b)
{
for(int i=0;a[i]!=‘\0‘&&b[i]!=‘\0‘;i++)
if(a[i]!=b[i])
return 0;
return 1;
}
int main()
{
int n;
string str[1002];
while(cin>>n&&n)
{
int falg=1;
for(int i=0;i<n;i++)
cin>>str[i];
for(int i=0;i<n&&falg;i++)
for(int j=i+1;j<n;j++)
{
if(cmpstr(str[i],str[j]))
{
falg=0;
cout<<"NO"<<endl;
break;
}
}
if(falg==1) cout<<"YES"<<endl;
}
return 0;
}
山东省第一届ACM大学生程序设计竞赛(原题)—A—Phone Number,布布扣,bubuko.com
山东省第一届ACM大学生程序设计竞赛(原题)—A—Phone Number
原文:http://blog.csdn.net/lttree/article/details/23600489