zoukankan      html  css  js  c++  java
  • 洛谷P1106 删数问题

    如下。这可能是思路比较清晰的代码了。

    为了各位阅读方便,我将变量名加长了。

    谢谢阅读233

    #include<bits/stdc++.h>
    using namespace std;
    char ints[250];

    int main()
    {
    int n;
    cin>>ints>>n;
    int length;length = strlen(ints);
    static int currents[100];
    int currentCheckingDigit=1;
    int ptr=0;
    while (currentCheckingDigit<=length){
    if (n!=0){
    int min =10000;int rminat=0;//relative min at(numbers needed to be off)
    for (int i=ptr;i<=ptr+n;i++){
    if (ints[i]-'0'<min) {min=ints[i]-'0';rminat=i-ptr;}//find out the minium and where it is
    }
    for (int i=ptr;i<=ptr+rminat-1;i++){
    ints[i]='X';//everything before ptr+rminat will be elimated
    }

    n-=rminat;
    ptr+=rminat+1;
    currentCheckingDigit++;
    }
    else{
    currentCheckingDigit++;
    }
    }
    for (int i=0;i<=length-1;i++){
    if (ints[i]=='0'||ints[i]=='X') ints[i]='X';
    if (ints[i]!='0'&&ints[i]!='X') break;
    }
    for (int i=0;i<=length-1;i++) if (ints[i]!='X')cout<<ints[i];
    system("pause");
    return 0;
    }
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 No sacrifice , no victory.
  • 相关阅读:
    852. Peak Index in a Mountain Array
    841. Keys and Rooms
    832. Flipping an Image
    821. Shortest Distance to a Character
    824. Goat Latin
    如何生成git的公钥和私钥
    学习笔记
    加快JavaScript加载和执行效率
    PO BO VO DTO POJO DAO概念及其作用
    jvm 垃圾回收区的形象说明
  • 原文地址:https://www.cnblogs.com/pityhero233/p/7279894.html
Copyright © 2011-2022 走看看