Skip to content

Instantly share code, notes, and snippets.

@wildskyf
Last active October 30, 2015 09:04
Show Gist options
  • Save wildskyf/0382afee7b414acc52de to your computer and use it in GitHub Desktop.
Save wildskyf/0382afee7b414acc52de to your computer and use it in GitHub Desktop.
UVa 555
#include <stdio.h>
#include <algorithm>
#include <vector>
struct Card
{
operator int() const
{
switch(num)
{
case 'T':
return 10;
case 'J':
return 11;
case 'Q':
return 12;
case 'K':
return 13;
case 'A':
return 14;
default:
return num - '0';
}
}
char suit;
char num;
};
bool isBigger(Card c1, Card c2)
{
int c[2];
Card cards[2] = {c1, c2};
for(int i = 0; i < 2 ; ++i)
switch (cards[i].suit)
{
case 'C':
c[i] = 100;
break;
case 'D':
c[i] = 200;
break;
case 'S':
c[i] = 300;
break;
case 'H':
c[i] = 400;
break;
}
return c[0]+c1 < c[1]+c2;
}
using namespace std;
int main()
{
char firstPerson = 0;
while(1)
{
firstPerson = getchar();
if(firstPerson == '#') break;
else getchar();
int peopleNum = 0;
vector< vector<Card> > person = {};
vector<Card> cards;
person.assign(4,cards);
char pos[4] = {'E', 'S', 'W', 'N'};
switch(firstPerson)
{
case 'E':
peopleNum = 1;
break;
case 'S':
peopleNum = 2;
break;
case 'W':
peopleNum = 3;
break;
case 'N':
peopleNum = 0;
}
int out = 2;
while(out>0)
{
Card tmp;
tmp.suit = getchar();
if (tmp.suit == '\n')
{
--out;
continue;
}
tmp.num = getchar();
person[peopleNum%4].push_back(tmp);
++peopleNum;
}
for(int i = 0 ; i < 4 ; ++i)
stable_sort( person[i].begin(), person[i].end(), isBigger);
for(int i = 1 ; i < 5 ; ++i)
{
printf("%c:", pos[i%4]);
for(unsigned int j = 0 ; j < person[i%4].size() ; ++j)
printf(" %c%c", person[i%4][j].suit, person[i%4][j].num);
printf("\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment