题解 | #丢失的三个数#
丢失的三个数
http://www.nowcoder.com/practice/1b58fbb97bc048b8a4438173c5392167
#include<stdio.h>
#include<string.h>
int main()
{
int n;
int a[10000] = {0},b[3] = {0};
for(int i = 0;i<9777;i++){
scanf("%d",&n);
a[n] = 1;
}
int j = 0;
//三个数存在b[2]中
for(int i = 1;i<10000;i++){
if(a[i] == 0){
b[j] = i;
j++;
}
}
//排序b数组中的三个数 ,从小到大
int k = 0;
for(int i = 0;i<3;i++){
for(int j = i+1;j<3;j++){
if(b[j] < b[i]){
k = b[j];
b[j] = b[i];
b[i] = k;
}
}
for(int i = 0;i<2;i++){
if(b[i+1] <10)
cnt *=10;
else if(b[i+1]>=10 &&b[i+1]<100)
cnt *=100;
else if(b[i+1]>=100 &&b[i+1]<1000)
cnt *=1000;
else
cnt *=10000;
cnt += b[i+1];
}
printf("%ld", cnt%7);
return 0;
}
#include<string.h>
int main()
{
int n;
int a[10000] = {0},b[3] = {0};
for(int i = 0;i<9777;i++){
scanf("%d",&n);
a[n] = 1;
}
int j = 0;
//三个数存在b[2]中
for(int i = 1;i<10000;i++){
if(a[i] == 0){
b[j] = i;
j++;
}
}
//排序b数组中的三个数 ,从小到大
int k = 0;
for(int i = 0;i<3;i++){
for(int j = i+1;j<3;j++){
if(b[j] < b[i]){
k = b[j];
b[j] = b[i];
b[i] = k;
}
}
}
//这段不知道怎么用算法实现,只能硬解,请大佬指点
long int cnt = b[0];for(int i = 0;i<2;i++){
if(b[i+1] <10)
cnt *=10;
else if(b[i+1]>=10 &&b[i+1]<100)
cnt *=100;
else if(b[i+1]>=100 &&b[i+1]<1000)
cnt *=1000;
else
cnt *=10000;
cnt += b[i+1];
}
printf("%ld", cnt%7);
return 0;
}