Jishan's Log 7: Codeforces 118A solution
Codeforces 118A: String Task
What the problem wants?
This problem deals with strings (as the name suggests). The task is to take the string, and turn it into a format such that there are no vowels (a,e,i,y,o,u) and there are " . " s before the consonants.
Example: tour gets turned into => ".t.r".
How to solve it?
The Algorithm:
1) take string input
2) convert to lower-case
3) Iterate through the string. If the character is a vowel, skip it. Else add . then add the character to another string.
The Code:
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string StringBuilder(string s)
{
string str = "";
for_each(s.begin(), s.end(), [](char & c) {
c = tolower(c);
});
for(int i=0; i<s.length(); i++)
{
if(s[i] == 'a' || s[i] == 'o' || s[i] == 'y' || s[i] == 'e' || s[i] == 'u' || s[i] == 'i')
{
continue;
}
else
{
str += ".";
str += s[i];
}
}
return str;
}
int main()
{
fastio;
string word; cin >> word;
cout << StringBuilder(word) << "\n";
}
Comments
Post a Comment