zoukankan      html  css  js  c++  java
  • TOJ1153. Word Reversal

    1153.   Word Reversal
    Time Limit: 1.0 Seconds   Memory Limit: 65536K
    Total Runs: 5327   Accepted Runs: 2132    Multiple test files



    For each list of words, output a line with each word reversed without changing the order of the words.


    Input

    You will be given a number of test cases. The first line contains a positive integer indicating the number of cases to follow. Each case is given on a line containing a list of words separated by one space, and each word contains only uppercase and lowercase letters.


    Output

    For each test case, print the output on one line.


    Sample Input

    3
    I am happy today
    To be or not to be
    I want to win the practice contest
    


    Sample Output

    I ma yppah yadot
    oT eb ro ton ot eb
    I tnaw ot niw eht ecitcarp tsetnoc
    View Code
     1 #include<iostream>
     2 #include<stack>
     3 using namespace std;
     4 #include<string.h>
     5 #include<stdio.h>
     6 stack<char> s;
     7 char str[1000];
     8 int main()
     9 {
    10     int n,i,len;
    11     cin>>n;
    12     getchar();
    13     while(n--)
    14     {
    15        //cin>>str;
    16       gets(str);
    17        len=strlen(str);
    18        i=0;
    19        while(1)
    20        {
    21           while(str[i]!=' '&&i<len)
    22           {
    23               s.push(str[i]);
    24               i++;
    25           }
    26           while(!s.empty())
    27           {
    28              cout<<s.top();
    29              s.pop();
    30           }
    31           if(i!=len)
    32           {
    33               cout<<' ';
    34               i++;
    35           }
    36           else break;
    37         
    38        }
    39        cout<<endl;
    40           
    41   
    42     }
    43     return 0;
    44 }
    45           
    46           
  • 相关阅读:
    容斥原理学习(Hdu 4135,Hdu 1796)
    ACdream 1112
    CodeChef--Cards, bags and coins
    ACdream 1108(莫队)
    Hdu 2586(LCA)
    CodeChef--EQUAKE
    Hackerrank--Mixing proteins(Math)
    Clash Credenz 2014 Wild Card Round题解
    Codeforces 463D
    CodeChef August Lunchtime 2014 题解
  • 原文地址:https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_2012_08_010.html
Copyright © 2011-2022 走看看