• 蓝桥---错误票据(注意输入)


    Description

    某涉密单位下发了某种票据,并要在年终全部收回。
    每张票据有唯一的ID号。全年所有票据的ID号是连续的,但ID的开始数码是随机选定的。
    因为工作人员疏忽,在录入ID号的时候发生了一处错误,造成了某个ID断号,另外一个ID重号。
    你的任务是通过编程,找出断号的ID和重号的ID。
    假设断号不可能发生在最大和最小号。

    Input

    要求程序首先输入一个整数N(N<100)表示后面数据行数。
    接着读入N行数据。
    每行数据长度不等,是用空格分开的若干个(不大于100个)正整数(不大于100000),请注意行内和行末可能有多余的空格,你的程序需要能处理这些空格。
    每个整数代表一个ID号。

    Output

    要求程序输出1行,含两个整数m n,用空格分隔。
    其中,m表示断号ID,n表示重号ID

    Sample Input 1

    2
    5 6 8 11 9
    10 12 9

    Sample Output 1

    7 9

    Sample Input 2

    6
    164 178 108 109 180 155 141 159 104 182 179 118 137 184 115 124 125 129 168 196
    172 189 127 107 112 192 103 131 133 169 158
    128 102 110 148 139 157 140 195 197
    185 152 135 106 123 173 122 136 174 191 145 116 151 143 175 120 161 134 162 190
    149 138 142 146 199 126 165 156 153 193 144 166 170 121 171 132 101 194 187 188
    113 130 176 154 177 120 117 150 114 183 186 181 100 163 160 167 147 198 111 119

    Sample Output 2

    105 120

    这题超级简单,就是目前有几种方法过不了,先记下来

    AC代码:

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <stack>
    11 #include <map>
    12 #include <sstream>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 const int mod=1e9+7;
    16 const int maxn=1e7+10;
    17 using namespace std;
    18  
    19 int a[105];
    20 int tot;
    21  
    22 int main()
    23 {
    24     int T;
    25     cin>>T;
    26     tot=0;
    27     while(cin>>a[tot++]);
    28     sort(a,a+tot);
    29     int m,n;
    30     for(int i=1;i<tot;i++)
    31     {
    32         if(a[i]==a[i-1])
    33             n=a[i-1];
    34         else if(a[i]!=a[i-1]+1)
    35             m=a[i-1]+1;
    36     }
    37     cout<<m<<' '<<n<<endl;
    38     return 0;
    39 }

    由于一些不明原因wa掉的代码(也可能是oj数据问题):

    strtok

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <stack>
    11 #include <map>
    12 #include <sstream>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 const int mod=1e9+7;
    16 const int maxn=1e7+10;
    17 using namespace std;
    18 
    19 char str[maxn];
    20 int a[105];
    21 int tot;
    22 
    23 int F(char *ss)
    24 {
    25     int sum=0;
    26     for(int i=0;ss[i];i++)
    27     {
    28         sum=sum*10+ss[i]-'0';
    29     }
    30     return sum;
    31 }
    32 
    33 int main()
    34 {
    35     int T;
    36     scanf("%d",&T);
    37     getchar();
    38     while(T--)
    39     {
    40         gets(str);
    41         char *temp=strtok(str," ");
    42         while(temp)
    43         {
    44             a[tot++]=F(temp);
    45             temp=strtok(NULL," ");
    46         }
    47     }
    48     sort(a,a+tot);
    49     int m,n;
    50     for(int i=1;i<tot;i++)
    51     {
    52         if(a[i]==a[i-1])
    53             n=a[i-1];
    54         else if(a[i]!=a[i-1]+1)
    55             m=a[i-1]+1;
    56     }
    57     printf("%d %d
    ",m,n);
    58     return 0;
    59 }

    istringstream

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <stack>
    11 #include <map>
    12 #include <sstream>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 const int mod=1e9+7;
    16 const int maxn=1e7+10;
    17 using namespace std;
    18  
    19 string str;
    20 int a[105];
    21 int tot;
    22  
    23 int F(string ss)
    24 {
    25     int sum=0;
    26     for(int i=0;ss[i];i++)
    27     {
    28         sum=sum*10+ss[i]-'0';
    29     }
    30     return sum;
    31 }
    32  
    33 int main()
    34 {
    35     int T;
    36     cin>>T;
    37     getchar();
    38     while(T--)
    39     {
    40         getline(cin,str);
    41         istringstream it(str);
    42         string temp;
    43         while(it>>temp)
    44             a[tot++]=F(temp);
    45     }
    46     sort(a,a+tot);
    47     int m,n;
    48     for(int i=1;i<tot;i++)
    49     {
    50         if(a[i]==a[i-1])
    51             n=a[i-1];
    52         else if(a[i]!=a[i-1]+1)
    53             m=a[i-1]+1;
    54     }
    55     cout<<m<<' '<<n<<endl;
    56     return 0;
    57 }
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <stack>
    11 #include <map>
    12 #include <sstream>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 const int mod=1e9+7;
    16 const int maxn=1e7+10;
    17 using namespace std;
    18  
    19 string str;
    20 int a[105];
    21 int tot;
    22  
    23 int F(string ss)
    24 {
    25     int sum=0;
    26     for(int i=0;ss[i];i++)
    27     {
    28         sum=sum*10+ss[i]-'0';
    29     }
    30     return sum;
    31 }
    32  
    33 int main()
    34 {
    35     int T;
    36     cin>>T;
    37     getchar();
    38     tot=0;
    39     while(T--)
    40     {
    41         getline(cin,str);
    42         istringstream it(str);
    43         string temp;
    44         while(getline(it,temp,' '))
    45             a[tot++]=F(temp);
    46     }
    47     sort(a,a+tot);
    48     int m,n;
    49     for(int i=1;i<tot;i++)
    50     {
    51         if(a[i]==a[i-1])
    52             n=a[i-1];
    53         else if(a[i]!=a[i-1]+1)
    54             m=a[i-1]+1;
    55     }
    56     cout<<m<<' '<<n<<endl;
    57     return 0;
    58 }

     -

  • 相关阅读:
    Android Service 启动和停止服务
    Android 子线程中进行UI操作遇到的小问题
    JZ66 机器人的运动范围
    JZ65 矩阵中的路径
    JZ64 滑动窗口的最大值
    JZ63 数据流中的中位数
    Z62 二叉搜索树的第k个结点
    JZ61 序列化二叉树
    JZ60 把二叉树打印成多行
    JZ59 按之字形顺序打印二叉树
  • 原文地址:https://www.cnblogs.com/jiamian/p/11872922.html
Copyright © 2020-2023  润新知