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

一遍过~~~

Posted by shenhaomin at 2021-07-01 09:52:31 on Problem 3982
#include <iostream>
#include <cstring>

using namespace std;

char ans[1500];

void fun(char* a,char* b,char* c)
{
    memset(ans,0,sizeof(ans));
    int i=0,fa=strlen(a)-1,fb=strlen(b)-1,fc=strlen(c)-1,j;
    char t;
    int flag=3,op;
    while(flag)  //三个数都相加完毕才退出循环
    {
        if(ans[i]==0)
            op=0;
        else
            op=ans[i]-48;
        if(fa>=0)
        {
            op+=a[fa]-48;
            fa--;
            if(fa<0)
                flag--;
        }
        if(fb>=0)
        {
            op+=b[fb]-48;
            fb--;
            if(fb<0)
                flag--;
        }
        if(fc>=0)
        {
            op+=c[fc]-48;
            fc--;
            if(fc<0)
                flag--;
        }
        if(op>9)
        {
            ans[i++]=op%10+48;
            op/=10;
            ans[i]=op+48;
        }
        else
            ans[i++]=op+48;
    }
    for(i=1499;i>=0;i--)
        if(ans[i]!=0)
            break;
    for(j=0;j<(i+1)/2;j++)  //倒序
    {
        t=ans[j];
        ans[j]=ans[i-j];
        ans[i-j]=t;
    }
}

int main()
{
    int i;
    char ch1[1000],ch2[1000],ch3[1000];
    while(cin>>ch1>>ch2>>ch3)
    {
        for(i=3;i<100;i++)
        {
            fun(ch1,ch2,ch3);
            strcpy(ch1,ch2);
            strcpy(ch2,ch3);
            strcpy(ch3,ans);
        }
        cout<<ans<<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