zoukankan      html  css  js  c++  java
  • 啊哦!还是语言关

    把题目贴出来P1069

    写一个程序,从输入文件读入一对正整数,将这两个数之间(包括这两个数本身)的所有数按下述特别规则从小到大的顺序排序后输出,该特别规则是按两数倒过来的值进行比较决定其大小,如30倒过来为3,29倒过来为92,则29大于30。

    Write a program that reads a pair of positive integers from the input
    file, sorts those integers and the integers between them according to the reversal of their digits, and then prints those numbers, one number per line. The sort should print the smallest number first, largest number last. If two numbers reverse to the same number (e.g., 3 and 30, the smaller unreversed one should appear first in the output).
         

     

    我滴神啊!逆序输出不知道咋输出了!!!

    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct id
    {
    int xu;
    int daxiao;
    };
    id ida[110];
    
    
    int m,n,max=-6666666,x,y,a[110];
    
    
    void sortwork()
    {
    for(int i=1;i<n;i++)
    {
    bool flag=1;
    for(int j=1;j<=n-1;j++)
    if(ida[j].daxiao>ida[j+1].daxiao)
    {flag=0;swap(ida[j],ida[j+1]);}
    if(flag) break;
    }
    }
    void print()
    {
    for(int i=1;i<=n;i++)
    cout<<ida[i].xu<<endl;
    }
    
    
    void myswap(id &x,id &y) //交换
    {
    id temp;
    temp=x;x=y;y=temp;
    }
    
    
    
    int main()
    {
    cin>>x>>y;
    n=y-x+1;
    for(int i=1;i<=n;i++)
    {
    ida[i].xu=i+x-1;
    a[i]=ida[i].xu;
    }
    a[1]=x;
    
    for(int i=1;i<=n;i++)
    {
    for(;a[i]>0;)
    {
    ida[i].daxiao=(ida[i].daxiao+a[i]%10)*10;
    a[i]=a[i]/10;
    }
    }
    for(int i=1;i<=n;i++)
    ida[i].daxiao=ida[i].daxiao/10;
    sortwork();
    print();
    return 0;
    }


    没错就是标红字的地方是控制逆序输出的,然而呢,遇见末尾为0的数字还是会错。。。

    目前正在抢救中

    ********************************我是华丽丽的分割线***************************************

    以上编辑在6.16日

    好吧,上面的错误犯得比较低级;;;QzQ最重要的是,我居然没检查出来

    就是因为排序的地方越过了int的定义域,所以造成输出错误;;;;




    这么简单的错误居然困扰我一天。




    以后一定要改。。。敲打

    *************************以下是正确代码**********************

    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct id
    {
    int xu;
    long long daxiao;
    };
    id ida[110];
    
    
    
    
    int m,n,max=-6666666,x,y;long long a[110];
    
    
    
    
    void sortwork()
    {
    for(int i=1;i<n;i++)
    {
    bool flag=1;
    for(int j=1;j<=n-1;j++)
    if(ida[j].daxiao>ida[j+1].daxiao)
    {flag=0;swap(ida[j],ida[j+1]);}
    if(flag)  break;
    }
    }
    void print()
    {
    for(int i=1;i<=n;i++)
    cout<<ida[i].xu<<endl;
    }
    
    
    
    
    void myswap(id &x,id &y) //交换
    {
    id temp;
    temp=x;x=y;y=temp;
    }
    
    
    
    
    
    
    int main()
    {
    cin>>x>>y;
    n=y-x+1;
    for(int i=1;i<=n;i++)
    
    
    {
    ida[i].xu=i+x-1;
    a[i]=ida[i].xu;
    }
    a[1]=x;
    
    
    for(int i=1;i<=n;i++)
    {
    for(;a[i]>0;)
    {
    ida[i].daxiao=(ida[i].daxiao+a[i]%10)*10;
    a[i]=a[i]/10;
    }
    }
    for(int i=1;i<=n;i++)
    ida[i].daxiao=ida[i].daxiao/10;
    sortwork();
    print();
    return 0;
    }


  • 相关阅读:
    最详细的Vue Hello World应用开发步骤
    SAP Fiori + Vue = ?
    golang--连接redis数据库并进行增删查改
    golang--redis基本介绍
    golang--海量用户即时通讯系统
    (四十六)golang--网络编程(简易的聊天系统)
    动态规划--矿工挖矿
    (四十五)golang--反射
    动态规划--爬楼梯问题(入门)
    (四十四)golang--协程(goroutine)和管道(channel)相结合实例
  • 原文地址:https://www.cnblogs.com/supersumax/p/5882480.html
Copyright © 2011-2022 走看看