zoukankan      html  css  js  c++  java
  • 【HDOJ】1062 Text Reverse

    Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.

     
    Input
    The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
    Each test case contains a single line with several words. There will be at most 1000 characters in a line.
     
    Output
    For each test case, you should output the text which is processed.
     
    Sample Input
    3 olleh !dlrow m'I morf .udh I ekil .mca
     
    Sample Output
    hello world! I'm from hdu. I like acm.

    #include<iostream>
    #include<string>
    using namespace std;
    void main()
    {
    int T;
    while (cin>>T)
    {
    getchar();

    for (int i = 0; i < T; i++)
    {
    string str;
    getline(cin, str);
    int end = 0,top = 0;
    while (str[end] != '')
    {
    if (str[end]==' ')
    {
    for (int i = end-1; i >=top; i--)
    {
    cout << str[i];
    }

    cout << str[end];
    top = end + 1;
    }
    end++;
    }
    if (str[end]=='')
    {
    for (int i = end-1; i >=top-1; i--)
    {
    cout << str[i];
    }
    }
    cout << endl;
    }
    }
    }

  • 相关阅读:
    一步步实现ABAP后台导入EXCEL到数据库【1】
    CSS边框及常用样式
    CSS优先级
    CSS选择器
    label和fieldset标签
    img、列表和table标签
    a标签--超链接
    select标签和多行文本标签
    input标签
    body内常用标签
  • 原文地址:https://www.cnblogs.com/ruoh3kou/p/7105794.html
Copyright © 2011-2022 走看看