给你一个字符长度N,然后给你一个各个字符对应的数值,然后输出长为n总和最小的字符串、并且要按字点顺序输出。
View Code
#include<stdio.h> #include<string.h> #include<stdlib.h> char vowels[] = "AUEOI"; char conson[] = "JSBKTCLDMVNWFXGPYHQZR"; char odd[220]; char even[220]; int cmp(const void *a,const void *b) { return (*(char *)a-*(char *)b);//这个地方别写错了,我错了3次= = } int main() { int t,n,odd_n,even_n,i; int cas; cas = 0;//位置别写错了 while(~scanf("%d",&t)) { while(t--) { scanf("%d",&n); odd_n =n - n/2; even_n = n/2; int count; for(i = 0;i < odd_n;i++) { odd[i] = vowels[i/21]; } for(i = 0;i < even_n;i++) even[i] = conson[i/5]; qsort(odd,odd_n,sizeof(odd[0]),cmp); qsort(even,even_n,sizeof(even[0]),cmp); int j,k; j = k = 0; printf("Case %d: ",++cas); for(i = 1;i <= n;i ++) { if(i%2) printf("%c",odd[j++]); else printf("%c",even[k++]); } puts(""); } } return 0; }