您的位置:首页 > 其它

优先级队列的应用 之对扑克牌排序

2018-04-07 19:50 495 查看

#include <iostream>
#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
using namespace std;
struct node
{
char color;
char data;
int i;
node( char a= '0', char b= '0',int c=0 ):
color(a), data(b),i(c) {};
friend bool operator <(const node &a,const node &b)
{
return a.i>b.i;
}

};
char s[2];
char ans [105][3];
priority_queue<node> q[13];
int main()
{
int n;
cin >> n;

for(int i=0;i<n;i++)
{
scanf("%s",s);
char a=s[0];char b=s[1];
q[b-'0'-1].push(node(a,b,i));
}
int j=0;
for(int i=0;i<9;i++)
{
printf("Queue%d:",i+1);
int flag=1;
while(!q[i].empty())
{
if(flag==1)
{
printf("%c%c",q[i].top().color,q[i].top().data);
flag=0;
}
else
{
printf(" %c%c",q[i].top().color,q[i].top().data);
}
char a= q[i].top().color;char b=q[i].top().data;
q[a-'A'+9].push(node(a,b,j++));
q[i].pop();
}
printf("\n");
}
j=0;
for(int i=9;i<13;i++)
{
printf("Queue%c:",'A'+i-9);
int flag=1;
while(!q[i].empty())
{
if(flag)
{
printf("%c%c",q[i].top().color,q[i].top().data);
flag=0;
}
else
printf(" %c%c",q[i].top().color,q[i].top().data);
ans[j][0]=q[i].top().color;
ans[j][3]='\0';
ans[j++][1]=q[i].top().data;

q[i].pop();
}
cout <<endl;
}
for(int i=0;i<j;i++)
{
if(i==0)
cout<<ans[i];
else
cout << ' '<<ans[i];
}
cout << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: