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;
    }
    
  • 相关阅读:
    出现 could not open jvm.cfg 的解决办法
    powerdesigner相关概念理解
    UML建模类图
    LAMP环境折腾
    ThinkPHP学习笔记1
    ubuntu14在kDE界面下的关于eclipse提示框黑色背景的修改!
    LAMP环境安装与apache配置
    Unix网络编程---第四次作业
    Unix网络编程---第三次作业
    Unix网络编程---第二次作业
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308981.html
Copyright © 2011-2022 走看看