zoukankan      html  css  js  c++  java
  • 寻找最大数(三)

    寻找最大数(三)

    时间限制:1000 ms | 内存限制:65535 KB
    难度:2
    描述

    给出一个整数N,每次可以移动2个相邻数位上的数字,最多移动K次,得到一个新的整数。

    求这个新的整数的最大值是多少。

    输入
    多组测试数据。
    每组测试数据占一行,每行有两个数N和K (1 ≤ N≤ 10^18; 0 ≤ K ≤ 100).
    输出
    每组测试数据的输出占一行,输出移动后得到的新的整数的最大值。
    样例输入
    1990 1
    100 0
    9090000078001234 6
    样例输出
    9190
    100
    9907000008001234
    my answer:
    代码是很烂。。。。。。呜呜呜,学长写的类似选择排序呀有木有!而且不用考虑那么多细枝末节,好吧,多刷题吧,博客第一题竟然写的这么烂,交了4次呀大哭刷题刷题。。。。。走走。
    
    #include<iostream>
    #include<stdio.h>
    #include<cstring>
    #include<string>
    using namespace std;
    char a[100];
    int main()
    {
        int n;
        while(cin>>a)
        {
            cin>>n;
            int t=strlen(a);
            if(t==1){cout<<a<<endl;continue;}
            int max=0,i,b=0;
            while(n>0){
                max=b;
                for( i=max+1;i<t&&i-b<=n;i++){
                    if(a[max]<a[i])
                        max=i;
                }
                int j,temp=a[max];
                for(j=max;j>b;j--)
                    a[j]=a[j-1];
                a[b]=temp;
                n-=(max-b);
                b++;
                if(b==t-1)break;
            }
            cout<<a<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Django 基础教程
    Python之路【第十七篇】:Django【进阶篇 】
    Python之路【第十六篇】:Django【基础篇】
    Python之路【第十五篇】:Web框架
    AngularJS 教程
    jQuery
    最小公倍数生成树
    51nod 1743 雪之国度
    codeforces 633F The Chocolate Spree
    hihocoder 1246 王胖浩与环
  • 原文地址:https://www.cnblogs.com/NYNU-ACM/p/4248815.html
Copyright © 2011-2022 走看看