Monday, November 14, 2016

URI Solution 1234 solution - Dancing Sentence

URI Online Judge | 1234

Dancing Sentence

By TopCoder*  USA
Timelimit: 1
A sentence is called dancing if its first letter is uppercase and the case of each subsequent letter is the opposite of the previous letter. Spaces should be ignored when determining the case of a letter. For example, "A b Cd" is a dancing sentence because the first letter ('A') is uppercase, the next letter ('b') is lowercase, the next letter ('C') is uppercase, and the next letter ('d') is lowercase.

Input

The input contains several test cases. Each test case is composed by one line that contais a string sentence. This string will contain between 1 and 50 characters ('A'-'Z','a'-'z' or space ' '), inclusive, or at least, one letter ('A'-'Z','a'-'z').

Output

Turn the sentence into a dancing sentence (like following examples) by changing the cases of the letters where necessary. All spaces in the original sentence must be preserved, ie, " sentence " must be converted in " SeNtEnCe ".
Sample InputSample Output
This is a dancing sentence
  This   is         a  dancing   sentence 
aaaaaaaaaaa
z
ThIs Is A dAnCiNg SeNtEnCe
  ThIs   Is         A  dAnCiNg   SeNtEnCe 
AaAaAaAaAaA
Z


URI Solution 1234 solution - Dancing Sentence in C++ Language

#include <iostream>
#include <ctype.h>
using namespace std;
 
int main()
{
    string line;
    int ch;
 
    while(getline(cin, line))
    {
        ch = 0;
 
        for (int i = 0; i < line.size(); ++i)
        {
            if(line[i] != ' '){
                if(ch == 0){
                    ch = 1;
                    putchar(toupper(line[i]));
                }else{
                    ch = 0;
                    putchar(tolower(line[i]));
                }  
            }else{
                cout << " ";
            }
        }
        cout << endl;
    }
 
    return 0;
}

Download URI Solution 1234 Code from here:

Download Code:



1 comment:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.