1224 Problem Q- string reversal - Getting title - string handling -C ++ to achieve

Question Q: reverse a string

Time limit: 1 Sec Memory Limit: 32 MB
submitted: 196 solved: 73

Title Description

Small C likes to write words backwards, and now to a small line of text you write C, you can reverse each word and outputs them?

Entry

The input contains several test sample. The first line an integer T, the number of representatives of the test sample, followed by T test sample.
Each test sample per line, contains more than one word. His party have up to 1000 characters.

Export

For each test case, you should output the converted text.

Sample input  Copy

3 
olleh! Dlrow 
II of Figure .bulcm 
I EvoL .MCA

Sample output  Copy

hello world!
I like acmclub.
I love acm.

Code

​
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

char a[1050];
int main(){
    int N;
    cin>>N;
    getchar();
    while(N--){
        gets(a);
        int len =strlen(a);
        a[len]='\0';
        int i,j,k;
        j=-1;
        for(i=0;i<=len;i++){
            if(a[i]==' '||a[i]=='\0'){
                for( k = i-1;k>j;k--){
                    printf("%c",a[k]);
                    
                }
                if(a[i]!='\0'){
                    printf(" ");
                }
                j=i;
            }
        }
        printf("\n");
    }
    return 0;
}

​

 

Published 20 original articles · won praise 0 · Views 119

Guess you like

Origin blog.csdn.net/weixin_31789689/article/details/104736397