Topic 1525: Sub-string Reverse print
time limit:1 seconds
Memory limit:128 MB
Special question: No
submitted:2404
Resolution:388
-
Title Description:
-
Xiaoming has a lot of string cards, each string contains a number of consecutive spaces, and these cards in the process of printing each substring of the string is printed in reverse, now trouble you to help Xiao Ming the strings in the string correction, and in order to make the card beautiful, compressed in which the continuous space of 1.
-
Input:
-
The input contains multiple test cases, and the first line of each test case is a positive integer n,1=<n<=100000 that represents the length of the string on the card. The second line enters a string of length n (the string contains only lowercase letters and spaces). When n is 0 o'clock, represents the input end.
-
Output:
-
For each test case, output the corrected string as required.
-
Sample input:
-
3ABC13ABC EFG Hij
-
Sample output:
-
CBACBA GFE Jih
-
source :
- 2012 Google Campus Recruitment written question
#include <stdio.h> #include <string.h> #define MAX 100000+10char S[max];char tmp[max];int main () {int n; while (~SCANF ("%d", &n)) {if (n==0) return 0; while (GetChar ()! = ' \ n '); Gets (s); int Len=strlen (s); int i=0; while (i<len) {int j=0; while (i<len&&s[i]== ") {i++; j + +; } if (j>0) printf (""); j=0; while (i<len&&s[i]!= ") {tmp[j++]=s[i]; i++; } if (j>0) {for (int p=0,q=j-1;p<q;++p,--q) { Char T=tmp[p]; TMP[P]=TMP[Q]; tmp[q]=t; } tmp[j]= ' + '; printf ("%s", TMP); }} printf ("\ n"); } return 0;} /**************************problem:1525 User:kirchhoff language:c result:accepted time:40 ms memory:1112 kb****************************************************************/
Nine degrees OJ 1525 substring reverse print