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 geshenghua at 2013-09-16 23:38:06 on Problem 1026
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int keys[] = new int[n];
        int cycleLen[] = new int[n];
        char msg[] = new char[n];
        char resultMsg[] = new char[n];
        for (int i = 0; i < n; ++i) {
            keys[i] = in.nextInt();
        }
        for (int i = 0; i < n; ++i) {
            cycleLen[i] = 0;
        }
        for (int i = 0; i < n; ++i) {
            int nextKey = keys[keys[i] - 1];
            int cycles = 1;
            while (nextKey != keys[i]) {
                nextKey = keys[nextKey - 1];
                ++cycles;
            }
            cycleLen[i] = cycles;
        }
        int k = in.nextInt();

        while (k > 0) {
            String str = in.nextLine().trim();
            int index = 0;
            for (; index < str.length(); ++index) {
                msg[index] = str.charAt(index);
            }
            for (; index < n; ++index) {
                msg[index] = ' ';
            }

            for (int i = 0; i < n; ++i) {
                int currentKey = i + 1;
                for (int j = 0; j < k % cycleLen[i]; ++j) {
                    currentKey = keys[currentKey - 1];
                }
                resultMsg[currentKey - 1] = msg[i];
            }

            System.out.println(resultMsg);
            k = in.nextInt();
        }

        in.close();
    }
}

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