"First World War offer" Internet Internship Program Challenge

Source: Internet
Author: User

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

Related Article

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.