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