zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    (设计模式)组合模式
    redis 集群部署 (linux)
    redis 集群 配置文件
    redis 外部访问配置(bind正确配置)
    (设计模式)桥模式
    (springboot)freemarker(二)
    (springboot)入门(一)
    (设计模式)抽象工厂
    (设计模式)建造者模式
    (设计模式)原型
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308982.html
Copyright © 2011-2022 走看看