zoukankan      html  css  js  c++  java
  • [HDOJ3522]Minimum Integer sequence

    水题~

    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 }
  • 相关阅读:
    Spring Boot自动配置
    Servlet、JSP总结(1)
    Spring MVC
    Springboot中的数据库事务
    数据库访问
    AOP
    全注解下的IOC
    spring boot入门
    安卓工程化开发笔记(2)
    2048功能说明模板
  • 原文地址:https://www.cnblogs.com/debugcool/p/HDOJ3522.html
Copyright © 2011-2022 走看看