Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:自己的代码一直TLE,求大神帮忙检查一下

Posted by 08122224 at 2021-11-22 00:45:05 on Problem 3982
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator