Wednesday, September 16, 2015

The Mirror (CPROM UiTM Arau 2015)

Mirror is an object that reflects most of detailed physical characteristics of original light. In other word, you can create a duplicated image of identical physical characteristics using a mirror. Same goes when the string characters are placed in front of the mirror.

Input 
First line of input contains an integer N (1 ≤ N ≤ 5) to indicate number of test cases. Following the first line are the test cases. Each line of a test case contains a string data with character, C (C > 0).
The input must be read from standard input.

Output
The output of the program should display the original string concatenated with the mirrored string.
The output must be written to standard output.




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q10{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
            
      int cases = scan.nextInt();
      
      String [] ans = new String[cases];
            
      for(int x=0;x<cases;x++){
         String get = scan.next();
         
         StringBuilder str = new StringBuilder(get);
         get = get+str.reverse().toString();
         
         ans[x] = get;         
      }
      
      for(int x=0;x<cases;x++){
         System.out.println(ans[x]);
      }
   }
}


Judge Answer in Java


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import.java.util.Scanner;
public class Mirror {
    public static void main(String[] args) {
        Scanner sc = newScanner(System.in);
        intN = sc.nextInt();
        String testCase[] = new String[N];
        for (inti = 0; i < N; i++) {
            testCase[i] = sc.next();
        }
        for (inti = 0; i < N; i++) {
            for (intj = testCase[i].length() - 1; j >= 0; j--) {
                testCase[i] += testCase[i].charAt(j);
            }
            System.out.println(testCase[i]);
        }
        sc.close();
    }
}

No comments:

Post a Comment