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

递归算法 0MS 代码

Posted by kingsword at 2011-08-24 23:11:25 on Problem 2255
#include <iostream>
#include <cstring>
using namespace std;
char s1[33];
char s2[33];
char ans[33];
void build(int n,char* s1,char* s2,char* s)
{
    if(n <= 0) return ;
    int p = strchr(s2,s1[0]) - s2;
    build(p ,s1 + 1 , s2 ,s);
    build(n - p - 1 , s1 + p + 1, s2 + p + 1 , s + p);
    s[n - 1] = s1[0];
}
int main()
{
    while(cin >> s1 >> s2)
    {
        int n = strlen(s1);
        build(n,s1,s2,ans);
        ans[n] = '\0';
        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