• Codeforces 118A


    题目: A. String Task

    time limit per test: 2 seconds
    memory limit per test: 256 megabytes
    input: standard input
    output: standard output

    Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:

    deletes all the vowels,
    inserts a character “.” before each consonant,
    replaces all uppercase consonants with corresponding lowercase ones.

    Vowels are letters “A”, “O”, “Y”, “E”, “U”, “I”, and the rest are consonants. The program’s input is exactly one string, it should return the output as a single string, resulting after the program’s processing the initial string.

    Help Petya cope with this easy task.

    Input

    The first line represents input string of Petya’s program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.

    Output

    Print the resulting string. It is guaranteed that this string is not empty.

    Examples

    Input
    tour
    Output
    .t.r
    Input
    Codeforces
    Output
    .c.d.f.r.c.s
    Input
    aBAcAba
    Output
    .b.c.b

    思路:

    1.遍历给定的字符串,是元音字母就删除,同时i–;
    2.是辅音字母就将它转换成小写,在i位置插入’.’,同时i++;

    代码:

    #include<iostream>
    #include<string>
    using namespace std;
    bool isVowel(char c){
    	if(c=='a'||c=='o'||c=='y'||c=='e'||c=='u'||c=='i') return true;
    	if(c=='A'||c=='O'||c=='Y'||c=='E'||c=='U'||c=='I') return true;
    	return false;
    }
    int main(){
    	string s;
    	cin>>s;
    	for(int i=0;i<s.length();i++){
    		if(isVowel(s[i])) s.erase(i--,1);
    		else{
    			s[i]=tolower(s[i]);
    			s.insert(i++,".");
    		}
    	}
    	printf("%s",s.c_str());
    	return 0;
    }
    
  • 相关阅读:
    python os模块 常用命令
    将excel表格中的数据导入到SQL中
    临时数据表DataTable selected方法的使用
    ASP.NET数据库使用精典读取数据库中数据
    新兵开唱
    DropDownList控件的changed事件调用
    C# 读取Excel表格中的数据
    C# 强制类型转换示例
    用ADO.NET的ExecuteScalar方法返回单一值
    CentOS 6.3 桥接上网
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308981.html
Copyright © 2020-2023  润新知