Written for: http://codeforces.com/problemset/problem/118/A
Title Description
Give you a string, the string you need to do the following, and outputs the result of operation:
- Delete all the vowels in a string;
- Each consonants in the string is added in front of a character "."
- The string all uppercase letters to lower case letters
It should be noted that the question head teacher is Wang translated from codeforces over the top of the Russian people do not like to vowels awareness and English-speaking countries.
Russians are the "A", "O", "Y", "E", "U", "I" six English words as the vowels, and in addition to the six English words, the other 20 English words are consonants. It is to be noted!
Complete results of this task, the output string conversion.
Input Format
Input contains a single string, the string length between 1 and 100.
Output Format
The output of the character string conversion.
Sample input 1
tour
Sample output 1
.t.r
Sample input 2
Codeforces
Sample output 2
.c.d.f.r.c.s
Sample input 3
aBAcAba
Sample output 3
.b.c.b
Topic analysis
We need only to traverse each character in the string c.
First of all, if you encounter c is an uppercase letter, we first convert it to lowercase letters;
then, let us judge the lowercase letters, if it is a vowel, it is removed;
otherwise (consonants), will " . "+ c is added to the result string.
Finally outputs the result string.
Using the code char array to achieve the following:
#include <bits/stdc++.h>
using namespace std;
char ch[110];
const char vowels[] = "aoyeui";
int main() {
cin >> ch;
for (int i = 0; ch[i]; i ++) {
if (ch[i] >= 'A' && ch[i] <= 'Z') ch[i] += 32;
bool flag = false;
for (int j = 0; j < 6; j ++) {
if (ch[i] == vowels[j]) {
flag = true;
break;
}
}
if (flag == false) cout << "." << ch[i];
}
cout << endl;
return 0;
}
Using the code string to achieve the following:
#include <bits/stdc++.h>
using namespace std;
string s;
const string vowels = "aoyeui";
int main() {
cin >> s;
int n = s.length();
for (int i = 0; i < n; i ++) {
char c = s[i];
if (c >= 'A' && c <= 'Z') c += 32;
bool flag = false;
for (int j = 0; j < 6; j ++) {
if (c == vowels[j]) {
flag = true;
break;
}
}
if (flag == false) cout << "." << c;
}
cout << endl;
return 0;
}