求助!!!
  • 板块学术版
  • 楼主Graph_Theory
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/4/8 13:43
  • 上次更新2023/10/23 19:05:02
查看原帖
求助!!!
672044
Graph_Theory楼主2023/4/8 13:43

P8082 [COCI2011-2012#4] KEKS

//0分求助!!!
#include<bits/stdc++.h>
using namespace std;
stack<int> s,ans;
int getchar()//单字符读入
{
    char asd;cin>>asd;
    return asd-'0';
}
int main()
{
    //string a;
    int n,k;cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        int a=getchar();
 		if(!s.empty())
        {
            if(s.top()<a&&k>0)
            {
                s.pop();
                s.push(a);
                k--;
            }
            else s.push(a);
		}
        else s.push(a);
    }
    //输出
    int len=s.size();
    for(int i=1;i<=len;i++)
    {
        ans.push(s.top());//倒序
        s.pop();
    }
    for(int i=1;i<=len;i++) 
    {
        cout<<ans.top();//输出
        ans.pop();
    }
}


2023/4/8 13:43
加载中...