{ "question_id": 237159, "question_title": "按字典顺序排列问题", "question_content": "输入若干英文单词,将每个单词的首字母转换成大写字母,其他字母为小写,并按字典顺序排列", "difficulty": "中等", "answer_id": 216930, "answer_content": "\n\n```\n #include \n#include \n#include \n\nint cmp(const void * a, const void * b)\n{\n\treturn strcmp(*(char **)a, *(char **)b);\n}\n\nint main(int argc, char* argv[])\n{\n\tint n = 0;\n\tint i;\n\tprintf(\"how many words?\\n\");\n\tscanf(\"%d\", &n);\n\tchar ** s = new char *[n];\n\tfor (i = 0; i < n; i++)\n\t{\n\t\ts[i] = new char[100];\n\t\tscanf(\"%s\", s[i]);\n\t\tchar * t = s[i];\n\t\twhile (*t != '\\0')\n\t\t{\n\t\t\tif (t == s[i] && (*t >= 'a' && *t <= 'z')) *t = *t - 'a' + 'A';\n\t\t\tif (t > s[i] && (*t >= 'A' && *t <= 'Z')) *t = *t - 'A' + 'a';\n\t\t\tt++;\n\t\t}\n\t}\n\tqsort(s, n, sizeof(char *), cmp);\n\tfor (i = 0; i < n; i++)\n\t{\n\t\tprintf(\"%s\\n\", s[i]);\n\t}\n\treturn 0;\n}\n```\n\n\n\n```\n how many words?\n5\nwORd\nHellO\nyEllow\nshe\nAPPLE\nApple\nHello\nShe\nWord\nYellow\nPress any key to continue\n```\n\n", "tag_name": "c语言", "cpp": " #include \n#include \n#include \nint cmp(const void * a, const void * b)\n{\n\treturn strcmp(*(char **)a, *(char **)b);\n}\nint main(int argc, char* argv[])\n{\n\tint n = 0;\n\tint i;\n\tprintf(\"how many words?\\n\");\n\tscanf(\"%d\", &n);\n\tchar ** s = new char *[n];\n\tfor (i = 0; i < n; i++)\n\t{\n\t\ts[i] = new char[100];\n\t\tscanf(\"%s\", s[i]);\n\t\tchar * t = s[i];\n\t\twhile (*t != '\\0')\n\t\t{\n\t\t\tif (t == s[i] && (*t >= 'a' && *t <= 'z')) *t = *t - 'a' + 'A';\n\t\t\tif (t > s[i] && (*t >= 'A' && *t <= 'Z')) *t = *t - 'A' + 'a';\n\t\t\tt++;\n\t\t}\n\t}\n\tqsort(s, n, sizeof(char *), cmp);\n\tfor (i = 0; i < n; i++)\n\t{\n\t\tprintf(\"%s\\n\", s[i]);\n\t}\n\treturn 0;\n}", "topic_link": "https://bbs.csdn.net/topics/600470273", "status": 1, "keywords": "算法,排序", "license": "csdn.net", "notebook": { "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/111.ipynb?type=file" }, "notebook_enable": 1, "author": "oYangShiZi" }