2017 School recruit real problem programming training--sentence inversion inverted string

Source: Internet
Author: User
Tags time limit cmath
Time limit: 1 seconds space limit: 32768K heat index: 23758 algorithmic Knowledge video explanation Title DescriptionGiven a sentence (containing only letters and spaces), the word position in the sentence is reversed, the word is separated by a space, there is only one space between the words, and there are no spaces. For example: (1) "Hello Xiao Mi", "Mi xiao Hello" Input Description:
There are multiple groups of input data, one row for each group, with a sentence (sentence length less than 1000 characters)
Output Description:
For each test example, it is required to output sentences that are formed after the word reversal in the sentence
Example 1 input
Hello Xiao mi
Output
Mi Xiao Hello
#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include < algorithm> #include <string> #include <cstdlib> #include <stack> #include <map> #include <
set> #include <vector> #include <queue> using namespace std;
const int MAXN = 1005;
vector<string> Res;
string S;
    int main (void) {char TEMP[MAXN];
        while (Getline (cin,s)) {int len=s.length (), cnt=0;
                for (int i=0;i<len;i++) {if (s[i]== ') {if (cnt==0) continue;
                    else{temp[cnt]= ' + ';
                    Res.push_back (temp);
                cnt=0;
            }} else {temp[cnt++]=s[i];
            }} if (cnt!=0) {temp[cnt]= ' + ';
        Res.push_back (temp);
        } len=res.size ();
  for (int i=len-1;i>=0;i--)      {if (i==0) cout<<res[i]<<endl;
        else cout<<res[i]<< "";
}} return 0; }
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <queue>
using namespace std;
int main ()
{
    string s;
    while (Getline (cin,s))
    {
        int len=s.length ()-1;
        for (int i=len;i>0;i--)
        {
            if (s[i]== ')
            {
                cout<<s.substr (i+1), (len-i)) << ';
                len=i-1;
            }
        }
        Cout<<s.substr (0,len+1) <<endl;
    }
    return 0;
}
Time limit: 1 seconds space limit: 32768K heat index: 15675 algorithmic Knowledge video explanation Title DescriptionThe words are inverted and the punctuation is not inverted. such as I like Beijing. After the function becomes: Beijing. Like I Input Description:
Each test input consists of 1 test cases: I like Beijing. Input use case length not exceeding 100
Output Description:
Output the string after inverted, separated by a space
Example 1 input
I like Beijing.
Output
Beijing. Like I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.