某涉密单位下发了某种票据,并要在年终全部收回。
要求程序首先输入一个整数N(N<100)表示后面数据行数。
接着读入N行数据。
每行数据长度不等,是用空格分开的若干个(不大于100个)正整数(不大于100000)
每个整数代表一个ID号。
要求程序输出1行,含两个整数m n,用空格分隔。
其中,m表示断号ID,n表示重号ID
例如:
用户输入:
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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char str2[11000];
int a[11000]={0};
int cmp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main()
{
int n;
scanf("%d",&n);
getchar();
int count,i,j=0,k;
int m=0,z=0;
for(k=0;k<n;k++)
{
gets(str2);
for(i=0;i<strlen(str2);i++)
{
if(str2[i]!=' ')
{
a[j]=(a[j]*10)+(str2[i]-'0');
continue;
}
else
{
j++;
count=j;
}
}
j++;
}
/*for(i=0;i<=count;i++)
printf("%d ",a[i]);
putchar('\n');*/
qsort(a,count+1,sizeof(a[0]),cmp);
for (i = 0; i <=count; ++i)
{
if (a[i] == a[i+1])
z = a[i];
if (a[i]+2 == a[i+1])
m = a[i]+1;
if (m != 0 && z != 0)
break;
}
printf("%d %d\n",m,z);
return 0;
}