首页 > 其他 > 详细

UVa 490 - Rotating Sentences

时间:2014-12-23 13:59:27      阅读:1847      评论:0      收藏:0      [点我收藏+]

       字符串水题,旋转90度输出。注意字符串的长度和空格的处理。

code:

import java.util.*;

public class Main490 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char[][] str = new char[105][105];
		String s;
		int[] length = new int[105];
		int cnt = 0, mlen = 0;
		while(scan.hasNextLine()) {
			s = scan.nextLine();
			str[cnt] = s.toCharArray();
			length[cnt] = s.length();
			if(length[cnt] > mlen)
				mlen = length[cnt];
			cnt ++;
		}
		for(int i=0; i<mlen; i++) {
			for(int j=cnt-1; j>=0; j--){
				if(length[j] > i)
					System.out.print(str[j][i]);
				else
					System.out.print(" ");
			}
			System.out.println();
		}

	}

}


 

UVa 490 - Rotating Sentences

原文:http://blog.csdn.net/wxisme/article/details/42101395

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!