| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么几乎一样的两份代码,一个过了一个错了AC的代码:
#include<iostream>
#include<cstring>
using namespace std;
const int MAX = 100005;
static char str1[MAX] = {0},str2[MAX] = {0};
int main(){
while(cin>>str1>>str2){
int nLen1 = strlen(str1),nLen2 = strlen(str2);
if(nLen1 > nLen2){
printf("No\n");
continue;
}
if(strcmp(str1,str2) == 0){
printf("Yes\n");
continue;
}
int nPos1 = 0,nPos2 = 0;
for(;nPos1 < nLen1 && nPos2 < nLen2;++nPos2){
if(str2[nPos2] == str1[nPos1])++nPos1;
}
if(nPos1 == nLen1)printf("Yes\n");
else printf("No\n");
}
return 0;
}
WA的代码:
#include<iostream>
#include<cstring>
using namespace std;
const int MAX = 100005;
static char str1[MAX] = {0},str2[MAX] = {0};
int main(){
while(cin>>str1>>str2){
int nLen1 = strlen(str1),nLen2 = strlen(str2);
if(nLen1 > nLen2){
printf("No\n");
continue;
}
if(strcmp(str1,str2) == 0){
printf("Yes\n");
continue;
}
int i = 0,nPos = 0;
for(;i < nLen1;++i){
for(;nPos < nLen2;++nPos){
if(str2[nPos] == str1[i]){
++nPos;
break;
}
}
if(nPos == nLen2)break;
}
if(i == nLen1)printf("Yes\n");
else printf("No\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator