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

本地测所有数据均通过 提交无限WA 求解!!!

Posted by 14110581048 at 2015-06-10 03:45:33 on Problem 2506
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

char dp[333][11111];

char *Add(char *str1,char *str2)
{
    int i,k,j;
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    char str[11111];
    k = max(len1,len2);

    str[k+1] = 0;
    for(i = len1-1,j = len2-1; i >= 0 && j >= 0; --i,--j,--k)
    {
        str[k] = str1[i]+str2[j]-'0';
        if(str[k+1] > '9')
        {
            str[k] += 1;
            str[k+1] -= 10;
        }
    }
    while(j > -1)
    {
        str[k] = str2[j--];
        if(str[k+1] > '9')
        {
            str[k] += 1;
            str[k+1] -= 10;
        }
        --k;
    }
    while(i > -1)
    {
        str[k] = str1[i--];
        if(str[k+1] > '9')
        {
            str[k] += 1;
            str[k+1] -= 10;
        }
        --k;
    }
    if(str[k+1] > '9')
    {
        str[k] = '1';
        str[k+1] -= 10;
        return str;
    }else return str+1;

}

int main()
{

    int n;
    int i;
    strcpy(dp[0],"1");
    strcpy(dp[1],"1");
    for(i = 2; i <= 300; ++i)
        strcpy(dp[i],Add(dp[i-1],Add(dp[i-2],dp[i-2])));
    while(scanf("%d",&n)!= EOF)
    {
        printf("%s\n",dp[n]);
    }

    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