https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=424&mosmsg=Submission+received+with+ID+17582033
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn=new Scanner (System.in);
while(scn.hasNext()){
String str=scn.nextLine();
String arr[]=str.split(" ");
for(int i=0;i<arr.length;i++){
StringBuffer sb = new StringBuffer();
sb.append(arr[i]);
sb.reverse();
System.out.print(sb);
if(i!=arr.length-1)System.out.print(" ");
}
System.out.println("");
}
}
/*
題目:Q483: Word Scramble
作者:1010
時間:西元 2016 年 6 月 */
}
*補充(字串反轉)請將輸入的每一行字串,顛倒印出來。
import java.util.Scanner;
public class Reverse{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s;
s = sc.nextLine();
StringBuffer sb = new StringBuffer();
sb.append(s);
sb.reverse();
System.out.println(sb);
}
/*
題目:利用StringBuffer()呈現字串反轉
作者:1010
時間:西元 2016 年 6 月 */
}
Input:
Java
Output:
困難度 ★★avaJ
*這題要注意字串最尾巴不能也有空白必須用判斷式否則會Presentation error
沒有留言:
張貼留言