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;
    }
    
  • 相关阅读:
    MariaDB · 版本特性 · MariaDB 的 GTID 介绍
    stm8s 中断重复进入
    PCB积累
    链表的创建、增加、删除、改数据、遍历
    百度文库文字下载工具指引
    防倒灌的开关电路
    AD快速从原理图查找pcb中元件
    三目运算符填坑
    嵌入式结构化分层思想
    原码,反码,补码
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308982.html
Copyright © 2011-2022 走看看