多组输入,每行输入一个字母。
针对每组输入,输出为一行,如果输入字母是元音(包括大小写),输出“Vowel”,如果输入字母是非元音,输出“Consonant”。
A b
Vowel Consonant
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String str = "AaEeIiOoUu"; while(sc.hasNext()){ String s = sc.next(); if(str.contains(s)) System.out.println("Vowel"); else System.out.println("Consonant"); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); char ch; while(in.hasNext()) //表示是否将要有输入 { /*输入字符串再取第一个字符 (用字符串是因为没有nextChar()函数)*/ ch=in.next().charAt(0); //将字符统一转换为大写的,这样可以少写些判断条件 ch=Character.toUpperCase(ch); //判断语句 if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U') { System.out.println("Vowel");//是元音时输出 } else{ System.out.println("Consonant");//是辅音时输出 } } } }
#include<stdio.h> int main(){ char str; while(scanf("%c",&str)!=EOF){ getchar(); if(str=='a'||str=='e'||str=='i'||str=='o'||str=='u'||str=='A'||str=='E'||str=='I'||str=='O'||str=='U'){ printf("Vowel\n"); }else{ printf("Consonant\n"); } } }
#include<stdio.h> int main() { char ch = '0'; while (scanf("%c", &ch) != EOF) { //屏蔽回车\n if (ch == '\n' ) continue; if (ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' || ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' || ch == 'U' || ch == 'u') printf("Vowel\n"); else printf("Consonant\n"); } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner s = new Scanner(System.in); String[] num = {"A","E","I","O","U","a","e","i","o","u"}; boolean flag = false; while (s.hasNext()){ String i = s.next(); for(int j=0;j<num.length;j++){ if(i.equals(num[j])){ flag = true; } } if(flag){ System.out.println("Vowel"); flag = false; }else{ System.out.println("Consonant"); } } } }
只要有元素就匹配,不管是否出现其他元素import java.util.Scanner; import java.util.regex.Pattern; public class Test46 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); while(input.hasNext()) { String c=input.nextLine(); if(Pattern.compile(c,Pattern.CASE_INSENSITIVE).matcher("aeiouAEIOU").find()) System.out.println("Vowel"); else System.out.println("Consonant"); } } }
#include <stdio.h> #include <ctype.h> int main() { char c; while (scanf("%c", &c) != EOF) { c = tolower(c); if (c == '\n') printf("\n"); else if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') printf("Vowel"); else printf("Consonant"); } return 0; }
// Compiled in C++14(g++5.4) #include <bits/stdc++.h> using namespace std; int main() { string vowels = "aeiouAEIOU"; unordered_set<char> unset(vowels.begin(), vowels.end()); char ch; while (cin >> ch) { cin.get(); if (unset.find(ch) != unset.end()) { cout << "Vowel"; } else { cout << "Consonant"; } cout << endl; } return 0; }
#include <stdio.h> #include <ctype.h> int main(void) { int ch; while ((ch = getchar()) != EOF) { if (isspace(ch)) { continue; } ch = tolower(ch); if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { puts("Vowel"); } else { puts("Consonant"); } } return 0; }//库函数的运用;学C语言看C Primer Plus;
#include<stdio.h> int main() { char ch; while((ch=getchar())!=EOF){ getchar();//getchar()是去掉换行符 if(ch == 'a' || ch == 'A' || ch == 'E' || ch == 'e' || ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' || ch == 'U' || ch == 'u'){ printf("Vowel\n"); } else{ printf("Consonant\n"); } } return 0; }
#include <stdio.h> int main(){ char arrch[10] = {'A','a','E','e','I','i','O','o','U','u'}; char c = 0; while((scanf("%c",&c)) != EOF ){ int p = 0; for(int i = 0; i <= 9; i++){ if(c == arrch[i]){ p = 1; getchar(); break; } } if (p) { printf("Vowel\n"); }else{ printf("Consonant\n"); getchar(); } } }这个题可以用数组做,注意scanf带的'\n'
#include <stdio.h> int main(){ char ch; while(~scanf("%c", &ch)){ getchar(); if(ch == 'a' || ch == 'A' || ch == 'E' || ch == 'e' || ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' || ch == 'U' || ch == 'u'){ printf("Vowel\n");} else { printf("Consonant\n"); } } return 0; }
#include <stdio.h> int main() { char s[] = "aeiouAEIOU"; char* p = NULL; char input = 0; int flag = 0; while (scanf("%c", &input) != EOF) { //拿走空字符 getchar(); //重置p为字符串首元素 p = s; //重置标志为0 flag = 0; //判断是否为元音 while (*p) { if (*p == input) { flag = 1; break; } p++; } //进行相应输出 if (flag) { printf("Vowel\n"); } else { printf("Consonant\n"); } } return 0; }
//BC53 判断是元音还是辅音 #include "stdio.h" int main(){ char ch; while((scanf("%c",&ch) != EOF)){ getchar(); if((ch=='A') || (ch=='E') || (ch=='I') || (ch=='O') || (ch=='U') || (ch=='a') || (ch=='e') || (ch=='i') || (ch=='o') || (ch=='u')){ printf("Vowel\n"); continue; } else { printf("Consonant\n"); } } return 0; }