zoukankan      html  css  js  c++  java
  • CSL 的字符串

    https://ac.nowcoder.com/acm/contest/551/D

    单调栈的神仙题,真的nb

    想法很简单,例如dcaad,

    1  d

    2  d --->  c (后面还有d,可以弹出d,然后再放置c)

    3  c --->   ca (后面没有c了,不能弹出c)

    4 ca -- >  ca (a在栈里不管他)

    5 ca --->  cad(b>a可以直接放置)

    所以答案cad

    #include<iostream>
    #include<stack>
    #include<algorithm>
    #include<vector>
    #include<string>
    #include<map>
    using namespace std;
    const int  maxn = 2e5 + 11;
    vector<int>G[200];
    map<char, int>cnt,vis;
    
    stack<char> ins;
    
    string sn, ans;
    
    int main() {
    	cin >> sn;
    
    	for (int i = 0; i < sn.size(); i++) {
    		cnt[sn[i]]++;
    	}
    
    	for (int i = 0; i < sn.size(); i++) {
    		cnt[sn[i]]--;
    		if (vis[sn[i]]) continue;
    
    		if (ins.size() == 0) {
    			ins.push(sn[i]);
    			vis[sn[i]] = 1;
    		}
    		else {
    			while (ins.size()) {
    				if (ins.top() < sn[i]) {
    					break;
    				}
    				else {//弹出
    					if (cnt[ins.top()] == 0) {//不能弹出了
    						break;
    					}
    					else {
    						vis[ins.top()] = 0;
    						ins.pop();
    					}
    				}
    			}
    			vis[sn[i]] = 1;
    			ins.push(sn[i]);
    		}
    	}
    	while (ins.size()) {
    		ans.push_back(ins.top());
    		ins.pop();
    	}
    	reverse(ans.begin(), ans.end());
    	cout << ans << endl;
    	return 0;
    }
    

      

    寻找真正的热爱
  • 相关阅读:
    Bluedroid介绍
    Android蓝牙介绍
    Android Bluetooth抓包
    Bluetooth LMP介绍
    Bluetooth Baseband介绍
    Bluetooth SDP介绍
    Bluetooth HFP介绍
    Bluetooth RFCOMM介绍
    Bluetooth L2CAP介绍
    Windows开发
  • 原文地址:https://www.cnblogs.com/lesning/p/13499932.html
Copyright © 2011-2022 走看看