1. 程式人生 > >2776. String Task

2776. String Task

2776. String Task

  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

說明:輸入一個字串,將這些字母(不論大小寫)從字串中刪除:"A", "O", "Y", "E", "U", "I",然後此字串的其他字元前新增一個小數點,輸出的字串都是小寫。總體的想法:先轉小寫,然後刪除指定字元,然後新增小數點,最後輸出。

import java.util.Scanner;

public class Test2776 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine().toLowerCase();
        char[] chArr = str.toCharArray();
        String vowels = "aeyiou";

        // 刪除母音字母(我又何必傻傻的真刪除這個字元呢,不如將該字元設定為其他值,在拼接的時候,判斷一下就行)
        for (int i = 0; i < chArr.length; i++) {
            if (vowels.indexOf(chArr[i]) != -1) {
                chArr[i]='1';
            }
        }
        
        str = "";
        
        // 在子音字母前新增小數點
        for (int i = 0; i < chArr.length; i++) {
            if(chArr[i]!='1'){
                str += "." + chArr[i];
            }
        }
        System.out.println(str);
        sc.close();
    }
}