Copy the vowels of a string to another string and sort them.

Source: Internet
Author: User
Problem description:
There is a string that may contain English letters (uppercase and lowercase), numbers, and special characters. Now you need to implement a function to select the vowels in the string and store them in another string, and sort the letters in the string from small to large (the lower-case vowels are in the front, and the upper-case vowels are in the back order ).
Note:
1. the vowels are A, E, I, O, U, A, E, I, O, U.
2. The selected vowels do not need to be removed.
 
The final output string. The lower-case vowels are listed at the top, and the upper-case vowels are listed at the back.
 
Required implementation functions:
Void sort_vowel (char * input, char * output );
Input: char * input, indicating the input string

Output: char * output, sorted vowel string


The C code is as follows:

#include<stdio.h>#include<stdlib.h>#include<ctype.h>#include<string.h>int cmp(const void* a, const void* b);int is_vowel(char a);void sort_vowel(char* input, char* output);int main(){char input[1000] = {'\0'};char output[200] = {'\0'};printf("please input the original str: ");gets(input);printf("the sorted vowel is: ");sort_vowel(input,output);return 0;}int cmp(const void* a, const void* b){return *(char*)a - *(char*)b;}int is_vowel(char a){if(a=='a' || a=='e' || a=='i' || a=='o' || a=='u' ||a=='A' || a=='E' || a=='I' || a=='O' || a=='U')return 1;elsereturn 0;}void sort_vowel(char* input, char* output){char low[100] = {'\0'};char up[100] ={'\0'};int low_index=0;int up_index=0;while(*input != '\0'){if(is_vowel(*input)){if(isupper(*input)){up[up_index++] = *input;input++;continue;}else{low[low_index++] = *input;input++;continue;}}input++;}qsort(up,strlen(up),sizeof(char),cmp);qsort(low,strlen(low),sizeof(char),cmp);strcat(low,up);strcpy(output,low);while(*output != '\0')printf("%c",*output++);printf("\n");}

Several groups of test cases are as follows:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.