UVa 490 - Rotating Sentences
字符串水题,旋转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(); } } }
作者:Pickle
声明:对于转载分享我是没有意见的,出于对博客园社区和作者的尊重一定要保留原文地址哈。
致读者:坚持写博客不容易,写高质量博客更难,我也在不断的学习和进步,希望和所有同路人一道用技术来改变生活。觉得有点用就点个赞哈。