在线编程:字符串的完美度
来源:互联网 发布:js实现下拉框 编辑:程序博客网 时间:2024/04/30 14:25
#include <stdlib.h>int perfect(const char *s){ char *p=s; int count_array[26]={0}; int count=26; int idle=0;
int i=0; to_upper(p); while(*p) count_array[*p++ - 'A']++; sort(&count_array); for(i=0;i<sizeof(count_array)/sizeof(int);i++) idle+=count_array[i]*count--; return idle;}void sort(int *array){ int i=0; int tmp=0; int j=0; for(i=0;i<26;i++) { for(j=i;j<26;j++) { if(array[j]>array[i]) { tmp=array[j]; array[j]=array[i]; array[i]=tmp; } } }}void to_upper(char *s){ while(*s) { if(*s > 96 &&*s <= 123) *s=*s-32; *s++; }}int main(){ char s[20]="DAD"; printf("pec is %d!\n",perfect(s));}
为什么没过呢?求看客指点
- 在线编程:字符串的完美度
- 挑战编程:字符串的完美度
- 编程挑战:字符串的完美度
- 字符串的完美度(pongo的编程挑战..)
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串的完美度
- 字符串完美度---庞果编程挑战
- 字符串的完美度总结
- <转>android单元测试
- Oracle 数据库的常用操作
- SQLite 事务处理
- IT管理总结
- JMeter测试问题:address already in use
- 在线编程:字符串的完美度
- tomcat 启动错误
- GetModuleFileName
- assert()函数用法总结
- 大卫谈学习
- SVN学习之-使用
- IE下实现placeholder效果的jquery插件
- hibernate 的Transformers的使用注意
- 重装系统后常见问题