华师大 OJ 3055

题目描述:点击打开链接



值得一提的是,对这里的题目描述要理解准确。




#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/******************************************************************************/
/*                                                                            */
/*  DON'T MODIFY main() function anyway!                                      */
/*                                                                            */
/******************************************************************************/
double orderTable[26];

void solve(); /* write function solve() to process one case of the problem    */
void init(){}


int main()
{  int i,t; init();
   scanf("%d\n",&t);
   for (i=0;i<t;i++)
   { printf("case #%d:\n",i);
     solve();
   }
   return 0;
}

//1. 输入
//2. 编写比较函数
//3. 调用qsort函数对字符串重排
//4. 输出

int cmp(const void *a,const void *b)
{
    char ch1,ch2;  //ch1,ch2为待比较的字母
     int p1,p2;         //p1,p2为ch1,ch2在字母顺序表中的序号
    ch1=*((char *)a);
    ch2=*((char *)b);
    if(ch1>='a'&&ch1<='z') p1=ch1-'a'; else p1=ch1-'A';
    if(ch2>='a'&&ch2<='z') p2=ch2-'a';  else p2=ch2-'A';
    if(orderTable[p2]>orderTable[p1])   return 1;  //按照字母使用频率由大到小重排
    else if(orderTable[p2]==orderTable[p1])        //字母使用频率相同的情况
                    if(p1==p2) return ch2-ch1;  //相同字母,小写在大写前面
                    else  return p1-p2;
                               //不同字母,但使用频率相同,则按照字母表顺序排列
            else return -1;
}



void solve(){

    double tmp;
    char str[101];
    int i;
    for(i=0;i<25;i++){
        scanf("%lf",&orderTable[i]);
    }
    scanf("%lf\n",&orderTable[i]);
    gets(str);
    qsort(str,strlen(str),sizeof(char),cmp);
    printf("%s\n",str);

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值