上进小青年

导航

bored

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5375

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<string.h>
 5 using namespace std;
 6 int main()
 7 {
 8     char s1[10],s2[50];
 9     while(cin>>s1)
10     {
11         cin>>s2;
12         int len1[10],count=0;
13         memset(len1,0,sizeof(len1));
14         int l1=strlen(s1);
15         int l2=strlen(s2);
16         for(int i=0; i<l1; i++)
17         {
18             for(int j=0; j<l2; j++)
19             {
20                 if(s1[i]==s2[j])
21                 {
22                     len1[i]=j;
23                     count++;
24                     s2[j]=' ';
25                     break;
26                 }
27             }
28         }
29 
30         bool flag=true;
31         if(count!=l1)
32             flag=false;
33         else
34         for(int i=1; i<l1; i++)
35         {
36             if(len1[i]<len1[i-1])
37             {
38                 flag = false;
39                 break;
40             }
41         }
42         if(flag)cout<<"PASS"<<endl;
43         else cout<<"FAIL"<<endl;
44         memset(s1,NULL,sizeof(s1));
45         memset(s2,NULL,sizeof(s2));
46     }
47     return 0;
48 }
View Code

这个代码改啦好久,其实没有什么难得,但是却改啦好久,就是因为考虑问题不全面造成的,因为忘记考虑一种情况,就是有可能str1的字符串不能再str2中全部被找到,哎,今天做几道题,信心都被磨没啦,好伤心,但是,站起来,世界就是你的!!! 啊啊啊,加油

posted on 2016-08-04 22:29  上进小青年  阅读(149)  评论(0编辑  收藏  举报