| ||||||||||
| 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 | |||||||||
Re:自己的代码一直TLE,求大神帮忙检查一下In Reply To:自己的代码一直TLE,求大神帮忙检查一下 Posted by:1403mashaonan at 2015-01-23 12:23:23 > #include <iostream>
> #include<cstdio>
> #include<algorithm>
> #include<string>
> using namespace std;
> string pplus(string c,string d)
> {
> string str;
> int i,cha,x1=0,x2=0;
> string::size_type len1,len2;
> len1=c.size();
> len2=d.size();
> if(len1<len2)
> {
> cha=len2-len1;
> for(i=len1-1; i>=0; i--)
> {
> x1=((int)(d[cha+i]-'0')+(int)(c[i]-'0')+x2)%10;
> x2=((int)(d[cha+i]-'0')+(int)(c[i]-'0')+x2)/10;
> str=char(x1+48)+str;
> }
> for(i=cha-1; i>=0; i--)
> {
> x1=((int)(d[i]-'0')+x2)%10;
> x2=((int)(d[i]-'0')+x2)/10;
> str=char(x1+48)+str;
> }
> str=char(x2+48)+str;
> }
> else
> {
> cha=len1-len2;
> for(i=len2-1; i>=0; i--)
> {
> x1=((int)(c[cha+i]-'0')+(int)(d[i]-'0')+x2)%10;
> x2=((int)(c[cha+i]-'0')+(int)(d[i]-'0')+x2)/10;
> str=char(x1+48)+str;
> }
> for(i=cha-1; i>=0; i--)
> {
> x1=((int)(c[i]-'0')+x2)%10;
> x2=((int)(c[i]-'0')+x2)/10;
> str=char(x1+48)+str;
> }
> str=char(x2+48)+str;
> }
> for(;;)
> {
> if(str[0]=='0')
> str.erase(0,1);
> else
> break;
> }
> return str;
> }
> int main()
> {
> string str[105];
> while(cin>>str[0]>>str[1]>>str[2])
> {
> if(str[0][0]=='0'&&str[1][0]=='0'&&str[2][0]=='0')
> {
> printf("0\n");
> continue;
> }
> for(int i=3; i<=99; i++)
> {
> string temp;
> temp=pplus(str[i-1],str[i-2]);
> str[i]=pplus(str[i-3],temp);
> }
> cout<<str[99]<<endl;
> }
>
> return 0;
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator