| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
笨拙的代码 不要笑啊#include<stdio.h>
#include<math.h>
int main()
{
int i,k,sum = 0,j = 0;
char a[11] = {0};
scanf("%s",a);
for(i = 0;i<10;i++)
{
if(a[i] == 'X')
{
a[i] = 10 + '0';
}
if(a[i] == '?')
{
k = i;
}
else // if(a[i] != '?')
{
sum = sum + (a[i] - '0') * (10 - i);
}
}
if(k == 9)
{
for(i = 0;i<=10;i++)
{
if((sum + i*(10 - k))%11 == 0)
{
if(i == 10 && k == 9)
{
printf("X\n");break;
}
else if(i == 10 && k!= 9)
{
printf("-1\n");break;
}
else if(i!= 10)
{
printf("%d\n",i);break;
}
}
//sum = sum - i*(10 - k);
}
if(i == 11)
{
printf("-1\n");
}
}
else
{
for(i = 0;i<=9;i++)
{
sum = sum + i*(10 - k);
if(sum%11 == 0)
{
if(i == 10)
{
printf("X\n");break;
}
else
{
printf("%d\n",i);break;
}
}
sum = sum - i*(10 - k);
}
if(i == 10)
{
printf("-1\n");
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator