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           
  • 相关阅读:
    禁止网页后退
    C# 数组排序
    SQL求往年的工资和
    手机的隐秘功能
    C#中的String类
    C#修饰符
    Application,Session,Cookie,ViewState和Cache区别
    css margin和padding的区别
    php常见的js正则表达式
    js 正则表达式基础篇
  • 原文地址:https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_2012_08_010.html
Copyright © 2011-2022 走看看