English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Your printer has been infected by a virus and is printing gibberish. After staring at several printed pages for a while, you realize that it is printing every line inside-out. In other words, the left half of each line is being printed starting in the middle of the page and proceeding out toward the left margin. Similarly, the right half of each line is being printed starting at the right margin and proceeding in toward the middle of the page. For example, the line
THIS LINE IS GIBBERISH

is being printed as

I ENIL SIHTHSIREBBIG S
Your task is to write a program in C++/Java/C#, to unscramble a String line from its printed form back into its original order. You can assume that line contains an even number of characters.

2007-04-09 00:22:06 · 1 answers · asked by amit_pawar2007 1 in Computers & Internet Hardware Printers

1 answers

static String doit(String s) {
int i = s.size()/2;
String r = "";
for(int j=i;j>=0;j--) {
r = r + s.substring(j,1);
}

for(int j=s.size();j>i;j--) {
r = r + s.substring(j,1);
}

return s;
}

2007-04-09 00:33:19 · answer #1 · answered by gjmb1960 7 · 0 0

fedest.com, questions and answers