hiho week 107 register

Ended

Participants:535

Verdict:Accepted
Score:100 / 100
Submitted:2016-07-17 16:13:33

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <string>
#include <iostream>
using namespace std;
int main(){
    string temp;
    while(getline(cin, temp)){
        string lineOut = "";
        bool prevCharIsSpace = false;
        bool isCap = true;
        for(auto i = 0; i < temp.size(); ++i){
            if(lineOut == "" && isspace(temp[i])) continue;
            
            if(isalpha(temp[i])){
                if(isCap == true){
                    isCap = false;
                    lineOut += toupper(temp[i]);
                }else{
                    lineOut += tolower(temp[i]);
                }
                prevCharIsSpace = false;
            }
            if(ispunct(temp[i])){
                if(prevCharIsSpace == false) lineOut += temp[i];
                else lineOut[lineOut.size() - 1] = temp[i];
                lineOut += " ";
                if(temp[i] == '.') isCap = true;
                prevCharIsSpace = true;
            }
            if(isspace(temp[i])){
                if(prevCharIsSpace == true) continue;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX