1 solutions
-
0
C :
#include<stdio.h> int N; char str[1005]; int main() { while(scanf("%d%*c",&N)==1) while(N--) { gets(str); int i=0; while(str[i]) { while(str[i]==' ') { printf("%c",str[i++]); } int WordLeft=i; while(str[i]&&str[i]!=' ') { ++i; } int WordRight=i-1; while(WordLeft<=WordRight) { printf("%c",str[WordRight--]); } } printf("\n"); } return 0; }
Pascal :
program p1048; var st,s:ansistring; i,j,k,t:longint; begin readln(t); for i:=1 to t do begin readln(st); k:=pos(' ',st); while k<>0 do begin s:=copy(st,1,k-1); for j:=length(s) downto 1 do write(s[j]); write(' '); delete(st,1,k); k:=pos(' ',st); end; for j:=length(st) downto 1 do write(st[j]); writeln; end; end.
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = Integer.parseInt(in.nextLine()); while(t-->0){ String s = in.nextLine(); String[] ss = s.split(" "); StringBuffer sb = new StringBuffer(); for(int i=0;i<ss.length;i++){ StringBuffer tem = new StringBuffer(ss[i]); tem.reverse(); sb.append(" ").append(tem); } System.out.println(sb.toString().substring(1)); } } }
Information
- ID
- 799
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- # Submissions
- 6
- Accepted
- 3
- Uploaded By