2 5 6 8 11 9 10 12 9
7 9
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
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\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 }
原文:https://www.cnblogs.com/jiamian/p/11872922.html