输入若干英文单词,将每个单词的首字母转换成大写字母,其他字母为小写,并按字典顺序排列
5条回答 默认 最新
- threenewbee 2016-02-13 22:37关注
#include <stdio.h> #include <stdlib.h> #include <string.h> int cmp(const void * a, const void * b) { return strcmp(*(char **)a, *(char **)b); } int main(int argc, char* argv[]) { int n = 0; int i; printf("how many words?\n"); scanf("%d", &n); char ** s = new char *[n]; for (i = 0; i < n; i++) { s[i] = new char[100]; scanf("%s", s[i]); char * t = s[i]; while (*t != '\0') { if (t == s[i] && (*t >= 'a' && *t <= 'z')) *t = *t - 'a' + 'A'; if (t > s[i] && (*t >= 'A' && *t <= 'Z')) *t = *t - 'A' + 'a'; t++; } } qsort(s, n, sizeof(char *), cmp); for (i = 0; i < n; i++) { printf("%s\n", s[i]); } return 0; }
how many words? 5 wORd HellO yEllow she APPLE Apple Hello She Word Yellow Press any key to continue
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1
悬赏问题
- ¥15 stata合并季度数据和日度数据
- ¥15 c语言练习:统计词频
- ¥15 谁能提供rabbitmq,erlang,socat压缩包,记住版本要对应,发到邮箱2644980770@qq.com
- ¥15 谁能提供rabbitmq,erlang,socat压缩包,记住版本要对应
- ¥15 Vue3 中使用 `vue-router` 只能跳转到主页面?
- ¥15 用QT,进行QGIS二次开发,如何在添加栅格图层时,将黑白的矢量图渲染成彩色
- ¥50 监控摄像头 乐橙和家亲版 保存sd卡的文件怎么打开?视频怎么播放?
- ¥15 Python的Py-QT扩展库开发GUI
- ¥60 提问一下周期性信信号的问题
- ¥15 jtag连接不上fpga怎么办