码迷,mamicode.com
首页 > 其他好文 > 详细

元音字符识别复制

时间:2014-08-28 21:09:26      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   for   2014   问题   

将一个字符串的元音字母复制到另一个字符串,并排序(30分)

问题描述:

有一字符串,里面可能包含英文字母(大写、小写)、数字、特殊字符,现在需要实现一函数,将此字符串中的元音字母挑选出来,存入另一个字符串中,并对字符串中的字母进行从小到大的排序(小写的元音字母在前,大写的元音字母在后,依次有序)。

 

说明:

1、  元音字母是a,e,i,o,u,A,E,I,O,U。

2、  筛选出来的元音字母,不需要剔重(chong);

 

最终输出的字符串,小写元音字母排在前面,大写元音字母排在后面,依次有序。

 

要求实现函数:

void sortVowel (char* input, char* output);

【输入】  char* input,表示输入的字符串

【输出】  char* output,排好序之后的元音字符串。

【返回】  无

 

示例

输入:char *input = “Abort!May Be Some Errors In Out System. “

输出:char *output =“aeeeooouAEIO “

 

 1 #include<stdio.h>
 2 void sortVowel (char* input, char* output)
 3 {
 4     int c[256];
 5     int i;
 6     const char *p = input;
 7     for (i=0; i < 256; i++)
 8         c[i] = 0;
 9     while (*p != \0)
10     {
11         c[*p]++;
12         p++;
13     }
14     i = 0;
15     while (c[a] > 0)
16     {
17         output[i++] = a;
18         c[a]--;
19     }
20     while (c[e] > 0)
21     {
22         output[i++] = e;
23         c[e]--;
24     }
25     while (c[i] > 0)
26     {
27         output[i++] = i;
28         c[i]--;
29     }
30     while (c[o] > 0)
31     {
32         output[i++] = o;
33         c[o]--;
34     }
35     while (c[u] > 0)
36     {
37         output[i++] = u;
38         c[u]--;
39     }
40     while (c[A] > 0)
41     {
42         output[i++] = A;
43         c[A]--;
44     }
45     while (c[E] > 0)
46     {
47         output[i++] = E;
48         c[E]--;
49     }
50     while (c[I] > 0)
51     {
52         output[i++] = I;
53         c[I]--;
54     }
55     while (c[O] > 0)
56     {
57         output[i++] = O;
58         c[O]--;
59     }
60     while (c[U] > 0)
61     {
62         output[i++] = U;
63     }
64     output[i] = \0;
65 }
66 int main()
67 {
68     char in[30],out[30];
69     gets(in);
70     sortVowel(in,out);
71     printf("%s\n",out);
72 }

 

bubuko.com,布布扣

元音字符识别复制

标签:style   blog   http   color   io   ar   for   2014   问题   

原文地址:http://www.cnblogs.com/george-cw/p/3942362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!