Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求助,测试数据通过了但是一直WA,怀疑是输出格式的问题,试了各种格式都不行。求大神指点!!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator