-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplePigLatin.cpp
More file actions
74 lines (70 loc) · 1.58 KB
/
SimplePigLatin.cpp
File metadata and controls
74 lines (70 loc) · 1.58 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include <string>
#include <sstream>
#include <climits>
#include<iomanip>
/* */
using namespace std;
string pig_it(string str) {
string result;
string temp;
for (int i = 0; i < str.size(); i++)
{
if (isalpha(str[i]))
{
temp += str[i];
}
else
{
if (!(temp.empty()))
{
if (temp.size() > 1) {
result += temp.substr(1) + temp[0] + "ay";
}
else
{
result += temp + "ay";
}
temp.clear();
}
result += str[i];
}
}
if (!(temp.empty()))
{
if (temp.size() > 1) {
result += temp.substr(1) + temp[0] + "ay";
}
else
{
result += temp + "ay";
}
temp.clear();
} return result;
}
int main()
{
cout << pig_it("This is my string");
return 0;
}
/*Description:
Move the first letter of each word to the end of it,
then add "ay" to the end of the word. Leave punctuation marks untouched.
Examples
pigIt('Pig latin is cool'); // igPay atinlay siay oolcay
pigIt('Hello world !'); // elloHay orldway !
Regular Expressions
Algorithms*/
// /> フ
// | n n 彡
// /`ミ_xノ
// / |
// / ヽ ノ
// │ | | |
// / ̄| | | |
// | ( ̄ヽ__ヽ_)__)
// \二つ
// ITS CAT FOR YOU