107.json 2.4 KB
Newer Older
每日一练社区's avatar
test  
每日一练社区 已提交
1
{
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  "question_id": 1001511,
  "question_title": "采用插入排序,按照字符顺序从小到大进行排序",
  "question_content": "【问题描述】\n编写一个程序,从键盘接收一个字符串(长度不超过20),采用插入排序,按照字符顺序从小到大进行排序,最后输出排序后的字符串。\n【输入形式】\n输入一行字符串,长度不超过20。\n【输出形式】\n输出排序后的字符串。\n【样例输入】\nH2e3L*Lo,Wor#Ld.\n【样例输出】\n#*,.23HLLLWdeoor",
  "difficulty": "简单",
  "answer_id": 1179762,
  "answer_content": "# 问题解决的话,请点下采纳,以及之前的问题 https://ask.csdn.net/questions/1001509 也点下采纳,谢谢\n\n之前看错了下面是插入排序\n\n```\n#include <stdio.h>\n#include <string.h>\nint main()\n{\n    char a[21];\n    scanf(\"%s\",a);\n    int t,j=0,i=0;\n    int n = strlen(a);\n    for(j=1;j < n; j++){\n        for(i=0;i<j;i++) {\n            if (a[i] > a[j]) break;\n        }\n        int t=a[j];\n        int t1;\n        for(;i<=j;i++){\n\t\t\tt1=a[i];\n\t\t\ta[i]=t;\n\t\t\tt=t1;\n        }\n    }\n    printf(\"%s\",a);\n    return 0;\n}\n\n```\nhttps://ideone.com/QL7g22 在线调试通过\n\n\n下面是选择排序\n```\n#include <stdio.h>\n#include <string.h>\nint main()\n{\n\tchar a[21];\n\tscanf(\"%s\",a);\n\tint t,j=0,i=0;\n\tint n = strlen(a);\n\tfor(j=0;j < n - 1; j++){\n\t\tint min = j;\n\t\tfor(i=j+1;i < n; i++) {\n\t\t\tif (a[i] < a[min]) min=i;\n\t\t}\n\t\tif (min != j) {\n\t\t\tt=a[min];\n\t\t\ta[min]=a[j];\n\t\t\ta[j]=t;\n\t\t}\n\t}\n\tprintf(\"%s\",a);\n\treturn 0;\n}\n```",
  "tag_name": "c语言",
  "cpp": "#include <stdio.h>\n#include <string.h>\nint main()\n{\n\tchar a[21];\n\tscanf(\"%s\",a);\n\tint t,j=0,i=0;\n\tint n = strlen(a);\n\tfor(j=1;j < n; j++){\n\t\tfor(i=0;i<j;i++) {\n\t\t\tif (a[i] > a[j]) break;\n\t\t}\n\t\tint t=a[j];\n\t\tint t1;\n\t\tfor(;i<=j;i++){\n\t\t\tt1=a[i];\n\t\t\ta[i]=t;\n\t\t\tt=t1;\n\t\t}\n\t}\n\tprintf(\"%s\",a);\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600470272",
  "status": 1,
  "keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/107.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "taowei0210"
每日一练社区's avatar
test  
每日一练社区 已提交
19
}