OCAC Summer field B title game first string assignment problem solution

String mission
original title link: 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 the operation:
1, remove all vowels string;
. "" 2, add a character consonant in front of each string
3, all capital letters string converted into lowercase letters
to be noted that the question head Wang teacher is 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 containing a single string, the string length between 1 and 100.
[] Output format
output string after the conversion.
Sample input [1]
tour
[1] Sample Output
.tr
[2] Sample input
Codeforces
[2] sample output
.cdfrcs
[3] Sample input
aBAcAba
[3] Sample Output
.bc


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;
}

 

Guess you like

Origin www.cnblogs.com/ocac/p/11113417.html