Skip to content

Instantly share code, notes, and snippets.

@Me4ta
Created November 17, 2015 19:12
Show Gist options
  • Save Me4ta/c342b3e834908b6faf69 to your computer and use it in GitHub Desktop.
Save Me4ta/c342b3e834908b6faf69 to your computer and use it in GitHub Desktop.
Algorithm learning at "Women who code" class
#include<iostream>
#include<string>
using std::cout;
using std::string;
using std::cin;
using std::endl;
string piglatin(string word){
if(word.size() == 0){
return "Empty string";
}
else{
if((word[0] == 'b')||
(word[0] == 'c')||
(word[0] == 'd')||
(word[0] == 'f')||
(word[0] == 'g')||
(word[0] == 'h')||
(word[0] == 'j')||
(word[0] == 'k')||
(word[0] == 'l')||
(word[0] == 'm')||
(word[0] == 'n')||
(word[0] == 'p')||
(word[0] == 'q')||
(word[0] == 'r')||
(word[0] == 's')||
(word[0] == 't')||
(word[0] == 'w')||
(word[0] == 'v')||
(word[0] == 'x')||
(word[0] == 'z')){
char tmp = word[0];
int word_length = word.size();
int i=0;
for(i=0; i != word_length-1; i++){
word[i] = word[i+1];
}
word[i] = tmp;
word = word + "ay";
}
else{
return "Wrong word";
}
return word;
}
}
int unit_test(){
string test;
test = "";
cout << "Empty string test: " << piglatin(test) << endl;
test = "apple";
cout << "Test word is \"" << test << "\": " << piglatin(test) << endl;
test = "banana";
cout << "Test word is \"" << test << "\": " << piglatin(test) << endl;
}
int main(){
unit_test();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment