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 lzmagic at 2009-03-22 21:49:55 on Problem 1026
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char** argv)
{
    int n;
    vector<int> a(200), cir(200, -1);
    string str;

    int i, j, k, cnt;
    char pre, tmp;
    while (cin >> n && n != 0)
    {
        for (i = 0; i < n; --a[i], ++i) cin >> a[i];
        for (i = 0; i < n; ++i)
            if (cir[i] < 0) for (cir[i] = 1, j = i; a[j] != i; ++cir[i], j = a[j]) cir[a[j]] = 0;
        while (cin >> cnt && cnt != 0)
        {
            getchar();          // 郁闷,一定要这个。
            getline(cin, str);
            str.resize(n, ' ');
            for (i = 0; i < n; ++i)
                if (cir[i])
                    for (j = cnt % cir[i]; j > 0; --j)
                    {
                        pre = str[i];
                        for (k = a[i]; k != i; k = a[k]) { tmp = str[k]; str[k] = pre; pre = tmp; }
                        str[i] = pre;
                    }
            cout << str << endl;
        }
        cout << 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