统计元音(hdu20)

输入格式:输入一个整型,再循环输入带空格的字符串。

思考:先用scanf()函数输入一个整型,后面直接来个大循环,带空格字符串输入直接用gets()函数。

注意:由于scanf()里面多加了%c,&d,所以大循环前不用getchar()函数。

#include<stdio.h>
#include<cstring>
int main()
{
    int n;
    char d;
    char c[101];
    while (scanf_s("%d%c", &n, &d) != EOF)
    {
        for (int k = 1; k <= n; k++)
        {
            gets_s(c);
            int    d1 = strlen(c);
            int a = 0, e = 0, i = 0, o = 0, u = 0;
            for (int j = 0; j < d1; j++)
            {
                if (c[j] == ‘a‘)
                    a++;
                else if (c[j] == ‘e‘)
                    e++;
                else if (c[j] == ‘i‘)
                    i++;
                else if (c[j] == ‘o‘)
                    o++;
                else if (c[j] == ‘u‘)
                    u++;
            }
            printf("a:%d\n", a);
            printf("e:%d\n", e);
            printf("i:%d\n", i);
            printf("o:%d\n", o);
            printf("u:%d\n", u);
            if (k != n)
                printf("\n");
        }
    }
}
时间: 2024-08-09 16:59:41

统计元音(hdu20)的相关文章

1166: 零起点学算法73——统计元音

1166: 零起点学算法73--统计元音 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 1082  Accepted: 402[Submit][Status][Web Board] Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串,只由小写字母组成. Output 对于每个测试实例输出5行

c语言之统计元音

统计元音 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 45249    Accepted Submission(s): 18458 Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output 对于每个测

HDOJ 2027 统计元音

统计元音 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37878    Accepted Submission(s): 15559 Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output 对于每个测

hdu 2027 统计元音

统计元音 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 58391    Accepted Submission(s): 23254 Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output 对于每个测

统计元音

http://acm.hdu.edu.cn/showproblem.php?pid=2027 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 int main() 5 { 6 int n; 7 char a[102]; 8 scanf("%d",&n); 9 getchar(); 10 while(n--) 11 { 12 gets(a); 13 int l

hdu 2027 统计元音 (java)

问题: 注意for循环中参数,不要搞混了. 注意空行和换行的区别,题目是讲的不空行,但还是要进行换行. 统计元音 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 45831    Accepted Submission(s): 18695 Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数

百度练习题 统计元音字母

题目如下: 遇到一道题,苦苦没有思路,求各路python大神解答,在线等.输入一串文字,统计这串文字里的[元音字母(aeiou)大小写不分,A和a都统一算是a]的数量.有3个要求:1.打印出出现次数最少的元音字母和它的出现次数,如果出现次数为0的话就忽略不急.例如,“Are you about ”,里面没出现i, i就不算了.所以它打出来的东西就是“e with 1 occurence.”2.类似于“Andy was here”,a 和 e 都是出现次数最少的元音字母(2次),那么打出来就得是

统计元音(stringstream的-应用)

Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output 对于每个测试实例输出5行,格式如下:a:num1e:num2i:num3o:num4u:num5多个测试实例之间由一个空行隔开. 请特别注意:最后一块输出后面没有空行:) Sample Input 2 aeiou my name is ignatius Sample Output a:1 e:1 i:1 o

Problem K: 零起点学算法107——统计元音

#include<stdio.h> int main() { int n; char a[100]; while(scanf("%d%*c",&n)!=EOF) { while(n--) { int num1=0,num2=0,num3=0,num4=0,num5=0; gets(a); for(int i=0;a[i]!='\0';i++) { switch(a[i]) //在这用switch语句会比较方便 { case 'a': num1++;break; ca