題目
http://luckycat.kshs.kh.edu.tw/homework/q10340.htm
解題注意事項
1. ACM 禁止使用單行註解 // (會得到 Compilation error)
2. 注意內迴圈判斷完畢後,必須把 j+1,否則使用測試資料 aaaaa a 將會顯示 Yes
3. 注意 字串1 為 字串2 的結尾時, j == len2 的判斷式會成立的問題,所以要再加上 result == 0 的判斷
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100000], str2[100000];
int i, j, len1, len2;
int result;
while (fscanf(stdin, "%s %s", str1, str2))
{
if (feof(stdin)) break;
len1 = strlen(str1);
len2 = strlen(str2);
result = j = 0;
for (i=0; i<len1; i++)
{
if (result != 0) break;
for (; j<len2; j++)
{
if (str1[i] == str2[j])
{
j++;
if (i == len1-1)
{
result = 1;
}
break;
}
}
if (result == 0 && j == len2)
{
result = -1;
}
}
if (result == 1)
printf("Yesn");
else
printf("Non");
}
return 0;
}
文章標籤
全站熱搜
