1、 for(int i=s1.size()-1;i=0;i-) carry+=s1i-; carry+=s2i- c.insert(c.begin(),carry%10+ carry/=10; if(carry0) return c;大整数减法string BigSubtraction(string s1,string s2) string result; bool Flag=false; int carry=0,len1,len2; if(s1=s2) result=0return result; else if(s1.size()s2.size() swap(s1,s2); len1=s1.
2、size();len2=s2.size(); Flag=true; if(s1.size()=s2.size() & s1s2) swap(s1,s2); Flag=true; if(carry+(s1i-)-(s2i-) carry=carry+10+(s1i- result.insert(result.begin(),carry+ carry=-1; else carry=carry+(s1i- carry=0; int f=0; while(resultf=) result.erase(result.begin(); f+; if(Flag=true) result.insert(res
3、ult.begin(),- return result;大整数乘法string multiplication(string str1,string str2) int maxsize=200;/表示计算结果的长度 int a210,b210,c410;/分别为maxsize+10;maxsize+10;maxsize*2+10; int i; for(i=0;i i-)/把数字倒过来 aj+=str1i- for(j=0,i=len2-1; i-)/倒转第二个整数 bj+=str2i- ilen2; i+)/用第二个数乘以第一个数,每次一位 for(j=0; j=10) ci+1+=ci/10
4、; ci%=10; string Result= for(i=maxsize*2; (ci=0)&(i=0); i-);/跳过高位的 if(i=0) for(; Result+=ci+ Result= return Result;大整数除法求商#define MAX_LEN 200int an1MAX_LEN + 10;int an2MAX_LEN + 10;int aResultMAX_LEN + 10; int Substract( int * p1, int * p2, int nLen1, int nLen2) if( nLen1 = 0; i - ) if( p1i p2i ) br
5、eak; else if( p1i p2i ) return -1; for( i = 0; i nLen1; i + ) p1i -= p2i; if( p1i i -) an1j+ = s1i - int nLen2 =s2.size(); for( j = 0, i = nLen2 - 1; an2j+ = s2i - nLen2 ) Result= return Result; int nTimes = nLen1 - nLen2; if(nTimes 0) for( i = nLen1 -1;= nTimes; an2i = an2i-nTimes; for( ; i-) an2i
6、= 0; nLen2 = nLen1; for( j = 0 ; j = 0) nLen1 = nTmp; aResultnTimes-j+; for( i = MAX_LEN ; (i = 0) & (aResulti = 0); i - ); if( i = 0) Result+=aResulti+求N!#includemath.hint main() long m,i,j,a10000,n,c; while(scanf(%ld,&n) a0=1; m=0; for(i=1;=n;i+) c=0;=m; aj=aj*i+c; c=aj/10000; aj%=10000; if(c m+;
7、am=c; printf(,am); for(i=m-1;%4.4ld,ai);nFloyd(任意两点间的最短距离)/别人的测试代码 六度分离string.hiostreamusing namespace std;#define N 110#define MAX int gNNN,pathNN;int n,m; void floyd() for(int k=1;kgk-1ik+gk-1kj) gkij=gk-1ik+gk-1kj; %d%dn,&m)!=EOF) int i; for(i=1; if(i=j) g0ij=g0ji=0; else g0ij=g0ji=MAX; for(i=0;m; int x,y; scanf(x,&y); g0x+1y+1=g0y+1x+1=1; floyd(); i
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1