码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 数据结构---课后习题(第一章)


    🎈数据结构基础篇

    🎈👻👻课后习题

    🎈👻👻😅😅😅第一章算法设计

    🎈👻👻😅😅😅☀️☀️☀️☀️

    题目1.16:

      写一个算法自大至小的顺序一次输出顺序读取的三个数据x,y,z

    solution1(c++):第一次对所有排列组合数枚举,总共也就6种情况
    1. #include
    2. #include
    3. using namespace std;
    4. //输入三个整数,从大到小的顺序输出三个数据
    5. int main(){
    6. int x,y,z;
    7. cin>>x>>y>>z;
    8. if(x>=y&&y>=z){
    9. cout<
    10. }
    11. else if(x>=z&&z>=y){
    12. cout<
    13. }
    14. else if(y>=x&&x>=z){
    15. cout<
    16. }
    17. else if(y>=z&&z>=x){
    18. cout<
    19. }
    20. else if(z>=x&&x>=y){
    21. cout<
    22. }
    23. else if(z>=y&&y>=x){
    24. cout<
    25. }
    26. }

    输出检验(c++):

    soultion1(c):
    1. int main(){
    2. int x,y,z;
    3. scanf("%d %d %d",&x,&y,&z);
    4. if(x>=y&&y>=z){
    5. printf("%d,%d,%d",x,y,z);
    6. }
    7. else if(x>=z&&z>=y){
    8. printf("%d,%d,%d",x,z,y);
    9. }
    10. else if(y>=x&&x>=z){
    11. printf("%d,%d,%d",y,x,z);
    12. }
    13. else if(y>=z&&z>=x){
    14. printf("%d,%d,%d",y,z,x);
    15. }
    16. else if(z>=x&&x>=y){
    17. printf("%d,%d,%d",z,x,y);
    18. }
    19. else if(z>=y&&y>=x){
    20. printf("%d,%d,%d",z,y,x);
    21. }
    22. }

    输出检验(c):

    solution2(c++):利用if-else条件语句
    1. #include
    2. #include
    3. using namespace std;
    4. int main(){
    5. int x,y,z;
    6. cin>>x>>y>>z;
    7. int t1,t2;
    8. if (x>=y){
    9. t1 = x;
    10. t2 = y;
    11. }
    12. else{
    13. t1 = y;
    14. t2 = x;
    15. }
    16. if(z>=t1){
    17. cout<" "<" "<
    18. }
    19. else{
    20. if(z>=t2){
    21. cout<" "<" "<
    22. }
    23. else{
    24. cout<" "<" "<
    25. }
    26. }
    27. }

    输出检验(c++):

    solution2(c):
    1. int main(){
    2. int x,y,z;
    3. scanf("%d %d %d",&x,&y,&z);
    4. int t1,t2;
    5. if (x>=y){
    6. t1 = x;
    7. t2 = y;
    8. }
    9. else{
    10. t1 = y;
    11. t2 = x;
    12. }
    13. if(z>=t1){
    14. printf("%d %d %d",z,t1,t2);
    15. }
    16. else{
    17. if(z>=t2){
    18. printf("%d %d %d",t1,z,t2);
    19. }
    20. else{
    21. printf("%d %d %d",t1,t2,z);
    22. }
    23. }
    24. }

    输出检验(c):

    彩蛋:

      因为很长时间没有写过博客(bushi),算法实现能力远不及从前,代码写的很烂,主要目的还是便于自己日后复习使用。

  • 相关阅读:
    原子核内的相互作用
    HTML简单实现v-if与v-for与v-model
    PHP8中调换数组中的键值和元素值-PHP8知识详解
    Prometheus监控Linux主机(node-exporter)
    【JAVA学习笔记】63 -坦克大战1.3-敌方发射子弹,击中坦克消失并爆炸,敌人坦克随机移动,规定范围限制移动
    C#中List<T>的 AddRange方法使用说明
    Xilinx MIPI CSI-2 Receiver Subsystem IP详解
    目标检测模型的评价标准-AP与mAP
    Vue-62、Vue技术路由守卫
    eggjs controller层调用controller层解决方案
  • 原文地址:https://blog.csdn.net/weixin_54201782/article/details/133360712
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号