Skip to content

Instantly share code, notes, and snippets.

@sicknarlo
Created December 17, 2014 19:30
Show Gist options
  • Save sicknarlo/4033e17d62868f29c051 to your computer and use it in GitHub Desktop.
Save sicknarlo/4033e17d62868f29c051 to your computer and use it in GitHub Desktop.
[CodeEval] Roller Coaster
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int isLetter(int sasi);
//Tests to see if the character is a letter
int isUpper(int sasi);
//Returns 0 for capital letter, 1 for lower case
int main(){
string str;
while (getline(cin, str)){
int cap = 1; // 1=upper case
for (int i = 0; i < str.length(); i++){
int sasi = str[i];
if (isLetter(sasi) > 0){
if (isUpper(sasi) != cap){
if (isUpper(sasi) == 0){
sasi -= 32;
}
else if (isUpper(sasi) == 1){
sasi += 32;
}
}
if (cap == 0)
cap = 1;
else
cap = 0;
}
str[i] = sasi;
}
cout << str << endl;
}
system("pause");
return 0;
}
int isLetter(int sasi){
if ((sasi >= 65 && sasi <= 90) || (sasi >= 97 && sasi <= 122))
return 1;
else
return 0;
}
int isUpper(int sasi){
if (sasi >= 65 && sasi <= 90)
return 1;
else
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment