[求助]帮我看看程序哪里错了(绝对经典)
程序的题目是:9.Really Strange!!
成绩: 10 / 折扣: 0.8
Background
Raju has recently passed BSc. Engineering in Computer Science & Engineering from BUET ( Bangladesh University of Extraordinary Talents), the best university of Bangladesh. After passing, he has been appointed manager of BCS ( Bangladesh Calculation Society ). His first project is to visit a district and then to report the total number of distinct regions there. But, going there, he is astonished to see a very strange phenomena of the local people. He discovered that, the people make their area circular. Every two area have exactly two points to intersect and no three circles intersect in a common point. There are so many people so that it's very hard to calculate total number of distinct regions for Raju. So, only in this case he seeks for your help.
Input
The problem contains multiple test cases. You are given total number of circular area n in separate lines (n<=101000). And you know the number houses in the world can't be fraction or negative. Input is terminated by end of file.
Output
For each line of the input, your correct program should output the value of the total number of regions in separate lines for each value of n.
测试输入 期待的输出 时间限制 内存限制
测试用例 0 以文本方式显示 1 3
2 4
以文本方式显示 1 8
2 14
1秒 1024KB
我的程序是:
/*程序中主要是对公式m=n^2-n+2进行运算*/
#include<stdio.h>
#include<string.h>
void main()
{
int jisuan[2][10000],jieguo[100000],a,b,c,sum,k,m;
char shuru[10000],zhong[10000];
memset(shuru,'\x0',sizeof(shuru)); /*清零*/
memset(jisuan,0,sizeof(jisuan));
memset(jieguo,0,sizeof(jieguo));
memset(zhong,0,sizeof(zhong));
while(gets(shuru)!=NULL)
{ strcpy(zhong,shuru); /*将字符输入的数字转换到一个二维的int型数组中,方便后面的乘法运算*/
m=strlen(shuru);
for(b=0;m>0;m--,b++)
shuru[b]=zhong[m-1];
for(b=0;b<strlen(shuru);b++)
{
jisuan[0][9999-b]=shuru[b]-48;
jisuan[1][9999-b]=shuru[b]-48;
}
b=9999-b;
for(c=9999;c>b;c--) /*大数组的乘法运算*/
for(sum=9999,k=90000+c;sum>b;sum--,k--)
{
jieguo[k]=jieguo[k]+jisuan[0][c]*jisuan[1][sum];
if(jieguo[k]>9)
{
jieguo[k-1]=jieguo[k-1]+jieguo[k]/10;
jieguo[k]=jieguo[k]%10;
}
}
jisuan[0][9999]=jisuan[0][9999]-2; /*n-2操作*/
for(k=9999,c=99999;k>b;k--,c--) /*n^2-n操作*/
{
jieguo[c]=jieguo[c]-jisuan[0][k];
if(jieguo[c]<0)
{
jieguo[c-1]=jieguo[c-1]-1;
jieguo[c]=jieguo[c]+10;
}
}
for(b=0;jieguo[b]==0;b++);
for(;b<=99999;b++) /*输出*/
printf("%d",jieguo[b]);
printf("\n");
memset(jisuan,0,sizeof(jisuan));
memset(jieguo,0,sizeof(jieguo));
memset(shuru,'\x0',sizeof(shuru));
}
return 0;
}
这个程序是我先想好后再才敲出来的。发现对于10^n这种数失灵外,其他的都可以很好的计算出来,而且速度是超常的快。郁闷的就是对于10、100、1000、100000000000000000000000000000000……这样的数它总是不能正常的给出结果。
希望哪位高手帮我指点指点,我现在都郁闷死了~~~~~