1. String morphing
For a given string, we need to deform it in a linear (that is, O (n)) time. First, the string contains some spaces, just like "Hello World", and then we're going to reverse the words in a string separated by spaces, and reverse the case of each character. For example, "Hello World" is transformed into "World Hello".
Input Description:
Given a string s and its length n (1≤n≤500)
Output Description:
Please return the deformed string. The title guarantees that the given string is composed of uppercase and lowercase letters and spaces.
Input Example:
"This is a sample", 16
Output Example:
"SAMPLE A is this"
The code is as follows:
Class Transform {public: string trans (string s, int n) { string tmp; int cnt=0; for (int i=n-1;i>=0;i--) { if (s[i]>= ' a ' and s[i]<= ' z ') s[i]=toupper (S[i]); else if (s[i]>= ' A ' and s[i]<= ' Z ') s[i]=tolower (S[i]); else if (s[i]== ') { tmp+=s.substr (i+1,cnt); tmp+= "; cnt=0; Continue; } cnt++; if (i==0) { if (s[i]! = ") { tmp+=s.substr (i,cnt);}} } return tmp; }};
2.
"First World War offer" Internet Internship Program Challenge