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 |
新人VS2008下测试了几个数据都对 结果WA 求救基本是这样的:BigNum类中num数组里倒序存储整数值 每一个元素最大存储9999(由M定)。length为数组有效元素的个数 #include <stdio.h> #include <string.h> #define M 10000 #define MAX 7 class BigNum { public: BigNum(){length=0;memset(num,0,MAX);} BigNum operator *(int iNum); void PrintBigNum(); int num[MAX]; int length; }; void BigNum::PrintBigNum() { int i=length-1; printf("%d",num[i--]); for (;i>=0;i--) { int temp; if (num[i]==0) { temp=M+1; } else { temp=M/num[i]; } while (temp>10) { temp/=10; printf("0"); }//以上给每一位补前0 printf("%d",this->num[i]); } } BigNum BigNum::operator *(int iNum) { BigNum result; int i; int dy=0; for (i=0;i<this->length;i++) { int x=this->num[i]*iNum+dy; result.num[i]=x%M; dy=x/M; } result.num[i]=dy; result.length=this->length; if (dy) { result.length++; } return result; } BigNum Pow(int x,int y) { BigNum result; result.length=1; result.num[0]=1; for(int i=0;i<y;i++) { result=result*x; } return result; } int main() { int x,y; int i=0; scanf("%d %d",&x,&y); while (x!=0||y!=0) { BigNum bn=Pow(x,y); bn.PrintBigNum(); printf("\n"); scanf("%d %d",&x,&y); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator