[HDOJ3522]Minimum Integer sequence

來源:互聯網
上載者:User

水題~

View Code

1 #include <cstdio>
2 #include <cstring>
3
4 usingnamespace std;
5
6 constint SIZE =100005;
7
8 char opp1[SIZE];
9 char opp2[SIZE];
10
11 int main()
12 {
13 int ia;
14 int ib;
15
16 while (scanf("%s %s",opp1,opp2) != EOF)
17 {
18 int lena = strlen(opp1);
19 int lenb = strlen(opp2);
20
21 bool found =false;
22
23 int index =0;
24
25 for (ia =0,ib =0;ia < lena &&!found;ia++)
26 {
27 if (ib >= lenb) ib =0;
28
29 if (opp1[ia] == opp2[ib] && (ib ==0|| opp2[ib] == opp2[ib-1]))
30 {
31 ib++;
32 }
33 elseif (opp1[ia] <= opp2[ib] && (ib ==0|| opp1[ia] <= opp2[ib-1]))
34 {
35 ib =0;
36 index = ia +1;
37 if(ia == lena -1)
38 {
39 found =true;
40 }
41 }
42 elseif (ib !=0&& opp2[ib-1] < opp1[ia] && opp2[ib-1] <= opp2[ib])
43 {
44 found =true;
45 index = ia;
46 }
47 elseif (opp2[ib] < opp1[ia] && (ib ==0|| opp2[ib] <= opp2[ib-1]))
48 {
49 found =true;
50 }
51 }
52 //printf("%d %d\n",found,index);
53
54 if (!found)
55 {
56 int i;
57 for (i =0;i < lenb;i++)
58 if (opp2[i] != opp1[0])
59 break;
60 if (i == lenb) index =0;
61 else
62 if (opp2[i] < opp1[0]) index =0;
63 else index = lena;
64 }
65
66 for (int i =0;i < index;i++)
67 printf("%c",opp1[i]);
68 for (int i =0;i < lenb;i++)
69 printf("%c",opp2[i]);
70 for (int i = index;i < lena;i++)
71 printf("%c",opp1[i]);
72 printf("\n");
73
74 }
75 return0;
76 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.