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;
    }
    
  • 相关阅读:
    slf4j日志框架绑定机制
    Btrace使用入门
    JVM反调调用优化,导致发生大量异常时log4j2线程阻塞
    [转载]Javassist 使用指南(三)
    [转载]Javassist 使用指南(二)
    [转载]Javassist 使用指南(一)
    数组升序排序的方法Arrays.sort();的应用
    copyOfRange的应用
    copyOf数组复制方法的使用(数组扩容练习)
    binarySearch(int[] a,int fromIndex,int toIndex, int key)的用法
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308981.html
Copyright © 2011-2022 走看看