Poj2039 (基本题 decode一下就可以了)

import java.util.*;

public class Poj2039 {
	public static void main(String[]args)
	{
		Scanner scanner = new Scanner(System.in);
		while(true)
		{
			int w = Integer.parseInt(scanner.nextLine());
			if(w == 0)
			{
				break;
			}
			
			String str = scanner.nextLine();
			int len = str.length()/w;
			String[]items = new String[len];
			for(int i = 0; i < len; i++)
			{
				items[i] = str.substring(i*w, i*w+w);
				if(i%2==1)
				{
					items[i]=  reverse(items[i]);
				}
			}
			
			StringBuffer result = new StringBuffer();
			for(int j = 0; j < w; j++)
			{
				for(int i = 0; i < len; i++)
				{
					result.append(items[i].charAt(j));
				}
			}
			
			System.out.println(result.toString());
		}
	}
	
	static String reverse(String str)
	{
		StringBuffer sb =new StringBuffer();
		for(int i = str.length()-1; i>=0; i--)
		{
			sb.append(str.charAt(i));
		}
		
		return sb.toString();
	}
}

你可能感兴趣的:(java,J#)