Blue Bridge Cup wrong notes (note input)

 

Description

A secret unit sent down some notes, and to be fully recovered at the end of the year.
Each ticket has a unique ID number. All annual bill ID number is continuous, but the beginning of a digital ID is randomly selected.
Because of staff negligence, an error occurred when entering the ID number, resulting in a broken ID number, the other a heavy ID number.
Your task is programmed to find the ID ID number and weight of broken numbers.
Suppose off number unlikely to occur in the minimum and maximum number.

Input

The program first inputs required an integer N (N <100) represents the number of rows of data that follows.
Then reads the data of N lines.
Each row of unequal length, with a plurality of separated spaces (less than 100) positive integer (not more than 100,000), please note that the line may have extra spaces and end of the line, you need to be able to handle the program space.
Each integer representing an ID number.

Output

Program output line in claim 1, comprising two integers Mn, separated by spaces.
Wherein, m represents the number of broken ID, n represents the ID number of weight

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

 

This super-simple question, there are several ways that had not first down

 

AC Code:

 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 }

 

Due to some unknown reasons wa out code (which may also be a problem oj data):

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\n",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 }

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/jiamian/p/11872922.html