• Codeforces 1251C Minimize The Integer


    思路:

    1.所有奇数的顺序是固定的;所有偶数的顺序是固定的;
    2.将所有奇数偶数存在两个队列中,小的先出即可;

    代码:

    #define IOS ios::sync_with_stdio(false);cin.tie(0)
    #include<bits/stdc++.h>
    using namespace std;
    #define rp(i,n) for(int i=0;i<n;i++)
    #define rpn(i,n) for(int i=1;i<=n;i++)
    bool pty[100];//区分是否是奇数  
    int main(){
    	IOS;
    	int t;
    	cin>>t;
    	for(int i='1'-0;i<='9'-0;i+=2) pty[i]=true; 
    	rp(i,t){
    		string s;
    		cin>>s;
    		queue<char> odd,even;
    		for(auto e:s){
    			if(pty[e]) odd.push(e);
    			else even.push(e);
    		}
    		while(!odd.empty()&&!even.empty()){
    			if(odd.front()<even.front()){
    				cout<<odd.front();
    				odd.pop();
    			}else{
    				cout<<even.front();
    				even.pop();
    			}
    		}
    		while(!odd.empty()){
    			cout<<odd.front();
    			odd.pop();
    		}
    		while(!even.empty()){
    			cout<<even.front();
    			even.pop();
    		}
    		cout<<'
    ';
    	}
    	return 0;
    }
    
  • 相关阅读:
    2010浙大:zoj问题
    Meta 数据中文显示
    django 中间件
    url的配置
    django.contirb
    os模块
    线程和异步
    ADO.NET
    C#托管代码 CLR
    C#垃圾回收
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308890.html
Copyright © 2020-2023  润新知