mirror of
https://github.com/mx42/codingame.git
synced 2026-03-19 05:45:50 +01:00
Adding medium/hard puzzles & challenges...
This commit is contained in:
257
puzzles/medium/bender-episode-1.cpp
Normal file
257
puzzles/medium/bender-episode-1.cpp
Normal file
@@ -0,0 +1,257 @@
|
||||
// https://www.codingame.com/ide/puzzle/bender-episode-1
|
||||
// Xavier Morel - 2016-03-15
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#define LOOP 0
|
||||
#define WEST 1
|
||||
#define NORTH 2
|
||||
#define EAST 3
|
||||
#define SOUTH 4
|
||||
|
||||
#define EMPTY ' '
|
||||
#define DIR_WEST 'W'
|
||||
#define DIR_NORTH 'N'
|
||||
#define DIR_EAST 'E'
|
||||
#define DIR_SOUTH 'S'
|
||||
#define WALL '#'
|
||||
#define BRK_WALL 'X'
|
||||
#define START '@'
|
||||
#define END '$'
|
||||
#define BEER 'B'
|
||||
#define TELEPORTER 'T'
|
||||
#define INVERTER 'I'
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<string> map;
|
||||
|
||||
struct Coords {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
Coords () : x(0), y(0) {};
|
||||
Coords (int x, int y) : x(x), y(y) {};
|
||||
};
|
||||
|
||||
struct Character {
|
||||
Coords pos;
|
||||
char dir = SOUTH;
|
||||
bool boosted = false;
|
||||
bool inverted = false;
|
||||
int brkWalls = 0;
|
||||
|
||||
void faceNextDirection(bool recursive_call)
|
||||
{
|
||||
if (inverted == true) {
|
||||
if (!recursive_call) {
|
||||
dir = WEST;
|
||||
return;
|
||||
}
|
||||
if (dir == WEST) {
|
||||
dir = NORTH;
|
||||
} else if (dir == NORTH) {
|
||||
dir = EAST;
|
||||
} else if (dir == EAST) {
|
||||
dir = SOUTH;
|
||||
} else if (dir == SOUTH) {
|
||||
dir = WEST;
|
||||
}
|
||||
} else {
|
||||
if (!recursive_call) {
|
||||
dir = SOUTH;
|
||||
return;
|
||||
}
|
||||
if (dir == SOUTH) {
|
||||
dir = EAST;
|
||||
} else if (dir == EAST) {
|
||||
dir = NORTH;
|
||||
} else if (dir == NORTH) {
|
||||
dir = WEST;
|
||||
} else if (dir == WEST) {
|
||||
dir = SOUTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
vector<Coords> getPositions(char type)
|
||||
{
|
||||
vector<Coords> res;
|
||||
for (int x = 0; x < map.size(); x++) {
|
||||
size_t y = 0;
|
||||
while ((y = map[x].find_first_of(type, y)) != string::npos) {
|
||||
res.push_back(Coords(x, y));
|
||||
y++;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
inline void clearCell(Coords pos)
|
||||
{
|
||||
map[pos.x].at(pos.y) = EMPTY;
|
||||
}
|
||||
|
||||
char getCurrentCellType(const Character &bender)
|
||||
{
|
||||
return map[bender.pos.x].at(bender.pos.y);
|
||||
}
|
||||
|
||||
Coords getNextCellPos(const Character &bender)
|
||||
{
|
||||
Coords next = bender.pos;
|
||||
switch (bender.dir) {
|
||||
case NORTH:
|
||||
next.x--;
|
||||
break;
|
||||
case SOUTH:
|
||||
next.x++;
|
||||
break;
|
||||
case WEST:
|
||||
next.y--;
|
||||
break;
|
||||
case EAST:
|
||||
next.y++;
|
||||
break;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
char getNextCellType(const Character &bender)
|
||||
{
|
||||
Coords next = getNextCellPos(bender);
|
||||
return map[next.x].at(next.y);
|
||||
}
|
||||
|
||||
char getDirection(Character &bender, bool recursive_call)
|
||||
{
|
||||
char nextNode = getNextCellType(bender);
|
||||
char dir = bender.dir;
|
||||
if (nextNode == WALL) {
|
||||
bender.faceNextDirection(recursive_call);
|
||||
return getDirection(bender, true);
|
||||
} else if (nextNode == BRK_WALL) {
|
||||
if (bender.boosted == false) {
|
||||
bender.faceNextDirection(recursive_call);
|
||||
return getDirection(bender, true);
|
||||
}
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
void teleportBender(Character &bender)
|
||||
{
|
||||
vector<Coords> poss = getPositions(TELEPORTER);
|
||||
for (Coords pos : poss) {
|
||||
if (bender.pos.x != pos.x || bender.pos.y != pos.y) {
|
||||
bender.pos = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cerr << "Teleport couldnt find other teleporter ?! Wtf ?" << endl;
|
||||
}
|
||||
|
||||
vector<int> getDirections(void)
|
||||
{
|
||||
vector<Character> history;
|
||||
Character bender;
|
||||
vector<int> dirs;
|
||||
|
||||
// Get initial pos.
|
||||
bender.pos = getPositions(START).front();
|
||||
clearCell(bender.pos);
|
||||
|
||||
int turns = 0;
|
||||
while (1) {
|
||||
// Check current cell and proceed as necessary (Teleporter, Beer, Inverter, new direction, break wall, ...)
|
||||
char currentCell = getCurrentCellType(bender);
|
||||
switch (currentCell) {
|
||||
case TELEPORTER:
|
||||
teleportBender(bender);
|
||||
break;
|
||||
case BEER:
|
||||
bender.boosted = bender.boosted ? false : true;
|
||||
break;
|
||||
case INVERTER:
|
||||
bender.inverted = bender.inverted ? false : true;
|
||||
break;
|
||||
case DIR_NORTH:
|
||||
bender.dir = NORTH;
|
||||
break;
|
||||
case DIR_SOUTH:
|
||||
bender.dir = SOUTH;
|
||||
break;
|
||||
case DIR_WEST:
|
||||
bender.dir = WEST;
|
||||
break;
|
||||
case DIR_EAST:
|
||||
bender.dir = EAST;
|
||||
break;
|
||||
case BRK_WALL: // We should be boosted here...
|
||||
if (!bender.boosted) {
|
||||
cerr << "WTF ?! On a breakable wall but not boosted ?!" << endl;
|
||||
}
|
||||
clearCell(bender.pos);
|
||||
break;
|
||||
case END:
|
||||
// YAY!
|
||||
return dirs;
|
||||
}
|
||||
// Check for next direction.
|
||||
char dir = getDirection(bender, false);
|
||||
// Append next direction to the stack.
|
||||
dirs.push_back(dir);
|
||||
// Move to the next cell.
|
||||
bender.pos = getNextCellPos(bender);
|
||||
// Check history for doubles with current status.
|
||||
// If loop: clean stuff + return vector<int>();
|
||||
// Save current status to the history.
|
||||
turns++;
|
||||
|
||||
// Crappy check for loops, hehe...
|
||||
if (turns > 200) {
|
||||
return vector<int>();
|
||||
}
|
||||
}
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int H = 0;
|
||||
int W = 0;
|
||||
cin >> H >> W; cin.ignore();
|
||||
for (int i = 0; i < H; i++) {
|
||||
string row;
|
||||
getline(cin, row);
|
||||
map.push_back(row);
|
||||
}
|
||||
|
||||
vector<int> dirs = getDirections();
|
||||
if (!dirs.size()) {
|
||||
cout << "LOOP" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int dir : dirs) {
|
||||
switch (dir) {
|
||||
case NORTH:
|
||||
cout << "NORTH" << endl;
|
||||
break;
|
||||
case SOUTH:
|
||||
cout << "SOUTH" << endl;
|
||||
break;
|
||||
case WEST:
|
||||
cout << "WEST" << endl;
|
||||
break;
|
||||
case EAST:
|
||||
cout << "EAST" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
69
puzzles/medium/conway-sequence.cpp
Normal file
69
puzzles/medium/conway-sequence.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// https://www.codingame.com/ide/puzzle/conway-sequence
|
||||
// Xavier Morel - 2016-03-23
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<int> line;
|
||||
|
||||
|
||||
void computeNextLine()
|
||||
{
|
||||
vector<int> next;
|
||||
|
||||
int curNb = 0;
|
||||
int qty = 0;
|
||||
|
||||
for (int n : line) {
|
||||
if (curNb != n) {
|
||||
if (curNb != 0) {
|
||||
next.push_back(qty);
|
||||
next.push_back(curNb);
|
||||
}
|
||||
curNb = n;
|
||||
qty = 1;
|
||||
} else {
|
||||
qty++;
|
||||
}
|
||||
}
|
||||
|
||||
if (curNb != 0) {
|
||||
next.push_back(qty);
|
||||
next.push_back(curNb);
|
||||
}
|
||||
|
||||
line = next;
|
||||
}
|
||||
|
||||
void printLine(ostream& out)
|
||||
{
|
||||
bool first = true;
|
||||
for (int n : line) {
|
||||
if (first == false) {
|
||||
out << " ";
|
||||
}
|
||||
out << n;
|
||||
first = false;
|
||||
}
|
||||
out << endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int R;
|
||||
cin >> R; cin.ignore();
|
||||
int L;
|
||||
cin >> L; cin.ignore();
|
||||
|
||||
line.push_back(R);
|
||||
|
||||
for (int i = 1; i < L; i++) {
|
||||
printLine(cerr);
|
||||
computeNextLine();
|
||||
}
|
||||
printLine(cout);
|
||||
}
|
||||
77
puzzles/medium/dont-panic-episode-1.cpp
Normal file
77
puzzles/medium/dont-panic-episode-1.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
// https://www.codingame.com/ide/puzzle/don't-panic-episode-1
|
||||
// Xavier Morel - 2016-03-14
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* Auto-generated code below aims at helping you parse
|
||||
* the standard input according to the problem statement.
|
||||
**/
|
||||
int main()
|
||||
{
|
||||
int nbFloors; // number of floors
|
||||
|
||||
int width; // width of the area
|
||||
int nbRounds; // maximum number of rounds
|
||||
int exitFloor; // floor on which the exit is found
|
||||
int exitPos; // position of the exit on its floor
|
||||
|
||||
int nbTotalClones; // number of generated clones
|
||||
int nbAdditionalElevators; // ignore (always zero)
|
||||
int nbElevators; // number of elevators
|
||||
cin >> nbFloors >> width >> nbRounds >> exitFloor >> exitPos >> nbTotalClones >> nbAdditionalElevators >> nbElevators; cin.ignore();
|
||||
|
||||
int floors[nbFloors];
|
||||
memset(floors, 0, nbFloors);
|
||||
floors[exitFloor] = exitPos;
|
||||
|
||||
for (int i = 0; i < nbElevators; i++) {
|
||||
int elevatorFloor; // floor on which this elevator is found
|
||||
int elevatorPos; // position of the elevator on its floor
|
||||
cin >> elevatorFloor >> elevatorPos; cin.ignore();
|
||||
floors[elevatorFloor] = elevatorPos;
|
||||
}
|
||||
|
||||
// bool firstTurn = true;
|
||||
|
||||
// game loop
|
||||
while (1) {
|
||||
int cloneFloor; // floor of the leading clone
|
||||
int clonePos; // position of the leading clone on its floor
|
||||
string direction; // direction of the leading clone: LEFT or RIGHT
|
||||
cin >> cloneFloor >> clonePos >> direction; cin.ignore();
|
||||
|
||||
// Write an action using cout. DON'T FORGET THE "<< endl"
|
||||
// To debug: cerr << "Debug messages..." << endl;
|
||||
|
||||
int prevDestPos = (cloneFloor > 0 ? floors[cloneFloor - 1] : -1);
|
||||
int destPos = floors[cloneFloor];
|
||||
cerr << "Clone " << clonePos << " " << destPos << endl;
|
||||
|
||||
if (cloneFloor == -1 && clonePos == -1 && direction == "NONE") {
|
||||
cerr << "no clone" << endl;
|
||||
cout << "WAIT" << endl;
|
||||
} else if (
|
||||
(clonePos == width - 1 && direction == "RIGHT")
|
||||
|| (clonePos == 0 && direction == "LEFT")
|
||||
) {
|
||||
cerr << "avoid laser" << endl;
|
||||
cout << "BLOCK" << endl;
|
||||
} else if (prevDestPos != clonePos && (
|
||||
(clonePos > destPos && direction != "LEFT")
|
||||
|| (clonePos < destPos && direction != "RIGHT")
|
||||
)
|
||||
) {
|
||||
cerr << "Not the right direction" << endl;
|
||||
cout << "BLOCK" << endl;
|
||||
} else {
|
||||
cerr << "..." << endl;
|
||||
cout << "WAIT" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
109
puzzles/medium/last-crusade-episode-1.cpp
Normal file
109
puzzles/medium/last-crusade-episode-1.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
// https://www.codingame.com/ide/puzzle/the-last-crusade-episode-1
|
||||
// Xavier Morel - 2016-03-16
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define FROM_LEFT 0
|
||||
#define FROM_TOP 1
|
||||
#define FROM_RIGHT 2
|
||||
|
||||
#define NOPE 0
|
||||
#define LEFT 1
|
||||
#define RIGHT 2
|
||||
#define BOTT 3
|
||||
|
||||
int types[14][3] = {
|
||||
// LEFT TOP RIGHT
|
||||
{NOPE, NOPE, NOPE}, // type 0
|
||||
{BOTT, BOTT, BOTT}, // type 1
|
||||
{RIGHT, NOPE, LEFT}, // type 2
|
||||
{NOPE, BOTT, NOPE}, // type 3
|
||||
{NOPE, LEFT, BOTT}, // type 4
|
||||
{BOTT, RIGHT, NOPE}, // type 5
|
||||
{RIGHT, NOPE, LEFT}, // type 6
|
||||
{NOPE, BOTT, BOTT}, // type 7
|
||||
{BOTT, NOPE, BOTT}, // type 8
|
||||
{BOTT, BOTT, NOPE}, // type 9
|
||||
{NOPE, LEFT, NOPE}, // type 10
|
||||
{NOPE, RIGHT, NOPE}, // type 11
|
||||
{NOPE, NOPE, BOTT}, // type 12
|
||||
{BOTT, NOPE, NOPE}
|
||||
};
|
||||
|
||||
int getDir(int type, int pos)
|
||||
{
|
||||
cerr << "Cell is of type " << type << " and entered from " << pos << endl;
|
||||
return types[type][pos];
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int W; // number of columns.
|
||||
int H; // number of rows.
|
||||
cin >> W >> H; cin.ignore();
|
||||
int grid[H+1][W+1];
|
||||
for (int i = 0; i < H; i++) {
|
||||
for (int j = 0; j < W; j++) {
|
||||
int x;
|
||||
cin >> x;
|
||||
cerr << x << endl;
|
||||
grid[i][j] = x;
|
||||
}
|
||||
cin.ignore();
|
||||
}
|
||||
int EX;
|
||||
cin >> EX; cin.ignore();
|
||||
|
||||
cerr << "Large: " << W << " Haut: " << H << endl;
|
||||
for (int i = 0; i < H; i++) {
|
||||
cerr << "|";
|
||||
for (int j = 0; j < W; j++) {
|
||||
cerr << grid[i][j] << " ";
|
||||
}
|
||||
cerr << endl;
|
||||
}
|
||||
cerr << "----------" << endl;
|
||||
|
||||
|
||||
// game loop
|
||||
while (1) {
|
||||
int XI;
|
||||
int YI;
|
||||
string pos_str;
|
||||
int pos;
|
||||
cin >> XI >> YI >> pos_str; cin.ignore();
|
||||
|
||||
if (pos_str == "TOP") {
|
||||
pos = FROM_TOP;
|
||||
} else if (pos_str == "LEFT") {
|
||||
pos = FROM_LEFT;
|
||||
} else if (pos_str == "RIGHT") {
|
||||
pos = FROM_RIGHT;
|
||||
} else {
|
||||
cerr << "Unrecognized entrance..." << endl;
|
||||
}
|
||||
|
||||
cerr << "Cell at " << XI << "x" << YI << endl;
|
||||
int dir = getDir(grid[YI][XI], pos);
|
||||
cerr << "Dir: " << dir << endl;
|
||||
switch (dir) {
|
||||
case LEFT:
|
||||
XI--;
|
||||
break;
|
||||
case RIGHT:
|
||||
XI++;
|
||||
break;
|
||||
case BOTT:
|
||||
YI++;
|
||||
break;
|
||||
default:
|
||||
cerr << "WUT?" << endl;
|
||||
}
|
||||
cout << XI << " " << YI << endl;
|
||||
}
|
||||
}
|
||||
131
puzzles/medium/mayan-calculation.cpp
Normal file
131
puzzles/medium/mayan-calculation.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
// https://www.codingame.com/ide/puzzle/mayan-calculation
|
||||
// Xavier Morel - 2016-03-15
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* Auto-generated code below aims at helping you parse
|
||||
* the standard input according to the problem statement.
|
||||
**/
|
||||
int main()
|
||||
{
|
||||
int L;
|
||||
int H;
|
||||
cin >> L >> H; cin.ignore();
|
||||
map<int, string> nums;
|
||||
for (int i = 0; i < H; i++) {
|
||||
string numeral;
|
||||
cin >> numeral; cin.ignore();
|
||||
for (int j = 0; j < 20; j++) {
|
||||
if (!nums.count(j)) {
|
||||
nums[j] = string();
|
||||
}
|
||||
nums[j] += numeral.substr(j*L, L);
|
||||
nums[j] += "\n";
|
||||
}
|
||||
}
|
||||
map<int, string> term1;
|
||||
int S1;
|
||||
cin >> S1; cin.ignore();
|
||||
for (int i = 0; i < S1; i++) {
|
||||
int numPow = floor(i/H);
|
||||
string num1Line;
|
||||
cin >> num1Line; cin.ignore();
|
||||
if (!term1.count(numPow)) {
|
||||
term1[numPow] = string();
|
||||
}
|
||||
term1[numPow] += num1Line;
|
||||
term1[numPow] += "\n";
|
||||
}
|
||||
|
||||
map<int, string> term2;
|
||||
int S2;
|
||||
cin >> S2; cin.ignore();
|
||||
for (int i = 0; i < S2; i++) {
|
||||
int numPow = floor(i/H);
|
||||
string num2Line;
|
||||
cin >> num2Line; cin.ignore();
|
||||
if (!term2.count(numPow)) {
|
||||
term2[numPow] = string();
|
||||
}
|
||||
term2[numPow] += num2Line;
|
||||
term2[numPow] += "\n";
|
||||
}
|
||||
string operation;
|
||||
cin >> operation; cin.ignore();
|
||||
|
||||
// cerr << "Numbers:" << endl;
|
||||
double number1 = 0;
|
||||
double number2 = 0;
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
// cerr << i << endl << nums[i] << endl;
|
||||
for (int j = 0; j < term1.size(); j++) {
|
||||
if (term1[j] == nums[i]) {
|
||||
int pw = term1.size() - j - 1;
|
||||
cerr << "Number1 += " << i << " * 20^ " << pw << endl;
|
||||
number1 += i * pow(20.0, pw);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < term2.size(); j++) {
|
||||
if (term2[j] == nums[i]) {
|
||||
int pw = term2.size() - j - 1;
|
||||
cerr << "Number2 += " << i << " * 20^ " << pw << endl;
|
||||
number2 += i * pow(20.0, pw);
|
||||
}
|
||||
}
|
||||
}
|
||||
// cerr << "term1:" << endl;
|
||||
// for (int i = 0; i < term1.size(); i++) {
|
||||
// cerr << term1[i] << endl;
|
||||
// }
|
||||
// cerr << number1 << endl;
|
||||
|
||||
// cerr << "term2:" << endl;
|
||||
// for (int i = 0; i < term2.size(); i++) {
|
||||
// cerr << term2[i] << endl;
|
||||
// }
|
||||
// cerr << number2 << endl;
|
||||
|
||||
cerr << number1 << operation << number2;
|
||||
|
||||
double res = 0;
|
||||
switch (operation.c_str()[0]) {
|
||||
case '+':
|
||||
res = number1 + number2;
|
||||
break;
|
||||
case '-':
|
||||
res = number1 - number2;
|
||||
break;
|
||||
case '/':
|
||||
res = number1 / number2;
|
||||
break;
|
||||
case '*':
|
||||
res = number1 * number2;
|
||||
break;
|
||||
}
|
||||
|
||||
cerr << " = " << res << endl;
|
||||
|
||||
bool started_to_write = false;
|
||||
for (int i = 64; i > 0; i--) {
|
||||
double curPow = pow(20.0, i - 1);
|
||||
if (curPow <= res) {
|
||||
int curNb = floor(res / curPow);
|
||||
cerr << "Current pow: " << curPow << " - nb: " << curNb << " = " << curPow * curNb << " (res " << res << ")" << endl;
|
||||
res -= (curNb * curPow);
|
||||
cout << nums[curNb];
|
||||
started_to_write = true;
|
||||
} else if (started_to_write == true) {
|
||||
cout << nums[0]; // endl should be included.
|
||||
}
|
||||
}
|
||||
if (started_to_write == false) {
|
||||
cout << nums[0];
|
||||
}
|
||||
}
|
||||
91
puzzles/medium/scrabble.cpp
Normal file
91
puzzles/medium/scrabble.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// https://www.codingame.com/ide/puzzle/scrabble
|
||||
// Xavier Morel - 2016-03-15
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct {
|
||||
string w;
|
||||
int val = 0;
|
||||
} Word;
|
||||
|
||||
Word getWord(string str)
|
||||
{
|
||||
Word res;
|
||||
res.w = str;
|
||||
res.val += std::count_if(str.begin(), str.end(), [](char c) {return c == 'q' || c == 'z';}) * 10;
|
||||
res.val += std::count_if(str.begin(), str.end(), [](char c) {return c == 'j' || c == 'x';}) * 8;
|
||||
res.val += std::count_if(str.begin(), str.end(), [](char c) {return c == 'k';}) * 5;
|
||||
res.val += std::count_if(str.begin(), str.end(), [](char c) {return c == 'f' || c == 'h' || c == 'v' || c == 'w' || c == 'y';}) * 4;
|
||||
res.val += std::count_if(str.begin(), str.end(), [](char c) {return c == 'b' || c == 'c' || c == 'm' || c == 'p';}) * 3;
|
||||
res.val += std::count_if(str.begin(), str.end(), [](char c) {return c == 'd' || c == 'g';}) * 2;
|
||||
res.val += std::count_if(str.begin(), str.end(), [](char c) {return c == 'e' || c == 'a' || c == 'i' || c == 'o' || c == 'n' || c == 'r' || c == 't' || c == 'l' || c == 's' || c == 'u';}) * 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool checkLetters(string word, string available)
|
||||
{
|
||||
// A bit redundant, but whatever.
|
||||
for (char c : available) {
|
||||
if (count(word.begin(), word.end(), c) > count(available.begin(), available.end(), c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-generated code below aims at helping you parse
|
||||
* the standard input according to the problem statement.
|
||||
**/
|
||||
int main()
|
||||
{
|
||||
int N;
|
||||
cin >> N; cin.ignore();
|
||||
vector<Word> dict;
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
string W;
|
||||
getline(cin, W);
|
||||
if (W.size() < 8) {
|
||||
dict.push_back(getWord(W));
|
||||
}
|
||||
}
|
||||
string LETTERS;
|
||||
getline(cin, LETTERS);
|
||||
|
||||
cerr << "Letters: " << LETTERS << endl;
|
||||
|
||||
Word *bestWord = 0;
|
||||
for (Word word : dict) {
|
||||
if (word.w.find_first_not_of(LETTERS) == string::npos) {
|
||||
if (!checkLetters(word.w, LETTERS)) {
|
||||
continue;
|
||||
}
|
||||
// Check for multiple letter occurrences...
|
||||
if (bestWord == 0 || word.val > bestWord->val) {
|
||||
cerr << "Word is best than stored one: " << word.w << endl;
|
||||
if (bestWord != 0) {
|
||||
delete bestWord;
|
||||
}
|
||||
bestWord = new Word(word);
|
||||
}
|
||||
} else {
|
||||
cerr << "Word with invalid letters: " << word.w << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// filtering of dict:
|
||||
// str.find_first_not_of(LETTERS)
|
||||
|
||||
// Write an action using cout. DON'T FORGET THE "<< endl"
|
||||
// To debug: cerr << "Debug messages..." << endl;
|
||||
|
||||
cout << bestWord->w << endl;
|
||||
delete bestWord;
|
||||
}
|
||||
80
puzzles/medium/shadow-of-the-knight-episode-1.cpp
Normal file
80
puzzles/medium/shadow-of-the-knight-episode-1.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
// https://www.codingame.com/ide/puzzle/shadows-of-the-knight-episode-1
|
||||
// Xavier Morel - 2016-03-14
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#define MIN 0
|
||||
#define MAX 1
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} Coords;
|
||||
|
||||
/**
|
||||
* Auto-generated code below aims at helping you parse
|
||||
* the standard input according to the problem statement.
|
||||
**/
|
||||
int main()
|
||||
{
|
||||
int W; // width of the building.
|
||||
int H; // height of the building.
|
||||
cin >> W >> H; cin.ignore();
|
||||
int N; // maximum number of turns before game over.
|
||||
cin >> N; cin.ignore();
|
||||
Coords pos;
|
||||
Coords range[2];
|
||||
|
||||
range[MIN].x = 0;
|
||||
range[MIN].y = 0;
|
||||
range[MAX].x = W - 1;
|
||||
range[MAX].y = H - 1;
|
||||
|
||||
cin >> pos.x >> pos.y; cin.ignore();
|
||||
|
||||
while (1) {
|
||||
string BOMB_DIR; // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
|
||||
cin >> BOMB_DIR; cin.ignore();
|
||||
|
||||
if (BOMB_DIR == "U") {
|
||||
range[MAX].y = pos.y - 1;
|
||||
} else if (BOMB_DIR == "UR") {
|
||||
range[MAX].y = pos.y - 1;
|
||||
range[MIN].x = pos.x;
|
||||
} else if (BOMB_DIR == "R") {
|
||||
range[MIN].x = pos.x;
|
||||
} else if (BOMB_DIR == "DR") {
|
||||
range[MIN].y = pos.y;
|
||||
range[MIN].x = pos.x;
|
||||
} else if (BOMB_DIR == "D") {
|
||||
range[MIN].y = pos.y;
|
||||
} else if (BOMB_DIR == "DL") {
|
||||
range[MIN].y = pos.y;
|
||||
range[MAX].x = pos.x - 1;
|
||||
} else if (BOMB_DIR == "L") {
|
||||
range[MAX].x = pos.x - 1;
|
||||
} else if (BOMB_DIR == "UL") {
|
||||
range[MAX].y = pos.y - 1;
|
||||
range[MAX].x = pos.x - 1;
|
||||
}
|
||||
|
||||
if (range[MAX].x != range[MIN].x) {
|
||||
pos.x = ceil((range[MAX].x + range[MIN].x) / 2.0f);
|
||||
} else {
|
||||
pos.x = range[MIN].x;
|
||||
}
|
||||
|
||||
if (range[MAX].y != range[MIN].y) {
|
||||
pos.y = ceil((range[MAX].y + range[MIN].y) / 2.0f);
|
||||
} else {
|
||||
pos.y = range[MIN].y;
|
||||
}
|
||||
|
||||
cout << pos.x << " " << pos.y << endl; // the location of the next window Batman should jump to.
|
||||
}
|
||||
}
|
||||
87
puzzles/medium/skynet-revolution-episode-1.cpp
Normal file
87
puzzles/medium/skynet-revolution-episode-1.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// https://www.codingame.com/ide/puzzle/skynet-revolution-episode-1
|
||||
// Xavier Morel - 2016-03-12
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct {
|
||||
bool is_gateway = false;
|
||||
vector<int> links;
|
||||
} Node;
|
||||
|
||||
Node *nodes;
|
||||
|
||||
void remove_link(int a, int b)
|
||||
{
|
||||
for (auto it = nodes[a].links.begin(); it != nodes[a].links.end(); it++) {
|
||||
if (*it == b) {
|
||||
nodes[a].links.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = nodes[b].links.begin(); it != nodes[b].links.end(); it++) {
|
||||
if (*it == a) {
|
||||
nodes[b].links.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
cout << a << " " << b << endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-generated code below aims at helping you parse
|
||||
* the standard input according to the problem statement.
|
||||
**/
|
||||
int main()
|
||||
{
|
||||
int N, L, E;
|
||||
cin >> N >> L >> E; cin.ignore();
|
||||
nodes = new Node[N];
|
||||
|
||||
for (int i = 0; i < L; i++) {
|
||||
int N1, N2;
|
||||
cin >> N1 >> N2; cin.ignore();
|
||||
nodes[N1].links.push_back(N2);
|
||||
nodes[N2].links.push_back(N1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < E; i++) {
|
||||
int EI;
|
||||
cin >> EI; cin.ignore();
|
||||
nodes[EI].is_gateway = true;
|
||||
}
|
||||
|
||||
// game loop
|
||||
while (1) {
|
||||
int SI;
|
||||
cin >> SI; cin.ignore();
|
||||
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
|
||||
for (int i : nodes[SI].links) {
|
||||
cerr << "Check node " << i << endl;
|
||||
if (nodes[i].is_gateway && nodes[i].links.size() > 0) {
|
||||
a = SI;
|
||||
b = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (a == 0 && b == 0) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (nodes[i].is_gateway && nodes[i].links.size() > 0) {
|
||||
a = i;
|
||||
b = nodes[i].links.back();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
remove_link(a, b);
|
||||
}
|
||||
}
|
||||
61
puzzles/medium/stock-exchange-losses.cpp
Normal file
61
puzzles/medium/stock-exchange-losses.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// https://www.codingame.com/ide/puzzle/stock-exchange-losses
|
||||
// Xavier Morel - 2016-03-16
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Auto-generated code below aims at helping you parse
|
||||
* the standard input according to the problem statement.
|
||||
**/
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n; cin.ignore();
|
||||
vector<int> history;
|
||||
int last_high = 0;
|
||||
int last_low = 0;
|
||||
int prev = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int v;
|
||||
cin >> v; cin.ignore();
|
||||
|
||||
if (i == 0) {
|
||||
last_high = v;
|
||||
last_low = v;
|
||||
continue;
|
||||
} else {
|
||||
if (v > last_high) {
|
||||
if (last_high != last_low) {
|
||||
history.push_back(last_high);
|
||||
history.push_back(last_low);
|
||||
}
|
||||
last_high = v;
|
||||
last_low = v;
|
||||
} else if (v < last_low) {
|
||||
last_low = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (last_high != last_low) {
|
||||
history.push_back(last_high);
|
||||
history.push_back(last_low);
|
||||
}
|
||||
|
||||
int max_loss = 0;
|
||||
for (vector<int>::iterator it = history.begin(); it != history.end(); it++) {
|
||||
int loss = *min_element(it, history.end()) - *it;
|
||||
if (loss < max_loss) {
|
||||
max_loss = loss;
|
||||
}
|
||||
}
|
||||
|
||||
cout << max_loss << endl;
|
||||
}
|
||||
74
puzzles/medium/teads-sponsored-contest.cpp
Normal file
74
puzzles/medium/teads-sponsored-contest.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// https://www.codingame.com/ide/puzzle/teads-sponsored-contest
|
||||
// Xavier Morel - 2016-03-17
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
map<int, vector<int>> points;
|
||||
|
||||
int findFarthestNode(int origin, int *distanceOut)
|
||||
{
|
||||
int maxDistance = 0;
|
||||
int farthestNode = 0;
|
||||
vector<pair<int,int>> process;
|
||||
|
||||
set<int> discovered;
|
||||
|
||||
process.push_back(pair<int,int>(origin,0));
|
||||
while (process.size() > 0) {
|
||||
pair<int,int> node = process.back(); // node, distance
|
||||
process.pop_back();
|
||||
discovered.insert(node.first);
|
||||
|
||||
if (node.second > maxDistance) {
|
||||
maxDistance = node.second;
|
||||
farthestNode = node.first;
|
||||
}
|
||||
|
||||
for (int adjNode : points[node.first]) {
|
||||
if (discovered.find(adjNode) == discovered.end()) {
|
||||
process.push_back(pair<int,int>(adjNode, node.second + 1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (distanceOut != 0) {
|
||||
*distanceOut = maxDistance;
|
||||
}
|
||||
|
||||
return farthestNode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n; cin.ignore();
|
||||
int firstNode;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int xi;
|
||||
int yi;
|
||||
cin >> xi >> yi; cin.ignore();
|
||||
points[xi].push_back(yi);
|
||||
points[yi].push_back(xi);
|
||||
if (i == 0) {
|
||||
firstNode = xi;
|
||||
}
|
||||
}
|
||||
|
||||
int distance;
|
||||
int farNode = findFarthestNode(firstNode, &distance);
|
||||
cerr << "Farthest node from origin is " << farNode << " with distance of " << distance << endl;
|
||||
farNode = findFarthestNode(farNode, &distance);
|
||||
cerr << "Farthest node from previous is " << farNode << " with distance of " << distance << endl;
|
||||
|
||||
cout << ceil(distance / 2.0f) << endl;
|
||||
}
|
||||
29
puzzles/medium/telephone-numbers.php
Normal file
29
puzzles/medium/telephone-numbers.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// https://www.codingame.com/ide/puzzle/telephone-numbers
|
||||
// Xavier Morel - 2016-03-17
|
||||
|
||||
$maintab = array();
|
||||
$lines = (int) fgets(STDIN);
|
||||
$result = 0;
|
||||
|
||||
$i = 0;
|
||||
while ($i < $lines) {
|
||||
$nbr = fgets(STDIN);
|
||||
$nbr = trim($nbr);
|
||||
|
||||
$c = strlen($nbr);
|
||||
$tab = &$maintab;
|
||||
for ($j = 0; $j < $c; $j++) {
|
||||
$number = $nbr[$j];
|
||||
if (!isset($tab[$number])) {
|
||||
$tab[$number] = array();
|
||||
$result++;
|
||||
$tab =& $tab[$number];
|
||||
} else {
|
||||
$tab =& $tab[$number];
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo $result;
|
||||
79
puzzles/medium/the-gift.cpp
Normal file
79
puzzles/medium/the-gift.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
// https://www.codingame.com/ide/puzzle/the-gift
|
||||
// Xavier Morel - 2016-03-14
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct {
|
||||
int number;
|
||||
int budget;
|
||||
int resp;
|
||||
} Ood;
|
||||
|
||||
/**
|
||||
* Auto-generated code below aims at helping you parse
|
||||
* the standard input according to the problem statement.
|
||||
**/
|
||||
int main()
|
||||
{
|
||||
int number;
|
||||
cin >> number; cin.ignore();
|
||||
int total_price;
|
||||
cin >> total_price; cin.ignore();
|
||||
int budget[number];
|
||||
int total_sum = 0;
|
||||
cerr << "Price: " << total_price << " for " << number << " people." << endl;
|
||||
for (int i = 0; i < number; i++) {
|
||||
cin >> budget[i]; cin.ignore();
|
||||
total_sum += budget[i];
|
||||
cerr << "Budget " << i << ": " << budget[i] << " (Total: " << total_sum << ")" << endl;
|
||||
}
|
||||
|
||||
if (total_sum < total_price) {
|
||||
cout << "IMPOSSIBLE" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int res[number];
|
||||
for (int i = 0; i < number; i++) {
|
||||
res[i] = 0;
|
||||
}
|
||||
|
||||
int left = total_price;
|
||||
while (left > 0) {
|
||||
int eq_parts = left / number;
|
||||
if (eq_parts == 0) {
|
||||
eq_parts = 1;
|
||||
}
|
||||
cerr << "Each ood should pay " << eq_parts << " (left: " << left << ")" << endl;
|
||||
for (int i = 0; i < number; i++) {
|
||||
if (left == 0) {
|
||||
break;
|
||||
}
|
||||
if (budget[i] >= eq_parts) {
|
||||
cerr << "Ood " << i << " can pay (budget " << budget[i] << ")" << endl;
|
||||
res[i] += eq_parts;
|
||||
left -= eq_parts;
|
||||
budget[i] -= eq_parts;
|
||||
cerr << "-> Will pay total " << res[i] << " (budget left: " << budget[i] << ")" << endl;
|
||||
} else {
|
||||
cerr << "Ood " << i << " cant pay that much" << endl;
|
||||
res[i] += budget[i];
|
||||
left -= budget[i];
|
||||
budget[i] = 0;
|
||||
cerr << "-> Will pay total " << res[i] << " (budget left: " << budget[i] << ")" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort(res, res + number);
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
cout << res[i] << endl;
|
||||
}
|
||||
}
|
||||
64
puzzles/medium/there-is-no-spoon-episode-1.cpp
Normal file
64
puzzles/medium/there-is-no-spoon-episode-1.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// https://www.codingame.com/ide/puzzle/there-is-no-spoon-episode-1
|
||||
// Xavier Morel - 2016-03-13
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define POS(x,y) ((width * y) + x)
|
||||
|
||||
/**
|
||||
* Don't let the machines win. You are humanity's last hope...
|
||||
**/
|
||||
int main()
|
||||
{
|
||||
int width; // the number of cells on the X axis
|
||||
cin >> width; cin.ignore();
|
||||
int height; // the number of cells on the Y axis
|
||||
cin >> height; cin.ignore();
|
||||
|
||||
char table[(width * height) + 1];
|
||||
|
||||
for (int i = 0; i < height; i++) {
|
||||
string line; // width characters, each either 0 or .
|
||||
getline(cin, line);
|
||||
memcpy(table + (width*i), line.c_str(), width);
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
if (*(table + POS(x, y)) == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
int rightof = -1;
|
||||
int below = -1;
|
||||
|
||||
for (int t = x + 1; t < width; t++) {
|
||||
if (*(table + POS(t, y)) == '0') {
|
||||
rightof = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int t = y + 1; t < height; t++) {
|
||||
if (*(table + POS(x, t)) == '0') {
|
||||
below = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout
|
||||
<< x << " "
|
||||
<< y << " "
|
||||
<< (rightof == -1 ? -1 : rightof) << " "
|
||||
<< (rightof == -1 ? -1 : y) << " "
|
||||
<< (below == -1 ? -1 : x) << " "
|
||||
<< (below == -1 ? -1 : below) << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
121
puzzles/medium/winamax-battle.cpp
Normal file
121
puzzles/medium/winamax-battle.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
// https://www.codingame.com/ide/puzzle/winamax-battle
|
||||
// Xavier Morel - 2016-03-14
|
||||
// WIP : only passing tests up to 88%...
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int parseCard(string card)
|
||||
{
|
||||
int num;
|
||||
card = card.substr(0, card.size() - 1);
|
||||
if (card == "J") {
|
||||
num = 11;
|
||||
} else if (card == "Q") {
|
||||
num = 12;
|
||||
} else if (card == "K") {
|
||||
num = 13;
|
||||
} else if (card == "A") {
|
||||
num = 14;
|
||||
} else {
|
||||
num = stoi(card);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
void moveCards(list<int> &winner, int card1, list<int> &stack1, int card2, list<int> &stack2)
|
||||
{
|
||||
while (stack1.size() > 0) {
|
||||
winner.push_back(stack1.front());
|
||||
stack1.pop_front();
|
||||
}
|
||||
winner.push_back(card1);
|
||||
while (stack2.size() > 0) {
|
||||
winner.push_back(stack2.front());
|
||||
stack2.pop_front();
|
||||
}
|
||||
winner.push_back(card2);
|
||||
}
|
||||
|
||||
void battleMove(list<int> &stack, int card, list<int> &cards)
|
||||
{
|
||||
stack.push_back(card);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (cards.size() == 0) {
|
||||
break;
|
||||
}
|
||||
stack.push_back(cards.front());
|
||||
cards.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
int runSimulation(list<int> &p1, list<int> &p2) {
|
||||
list<int> stack1;
|
||||
list<int> stack2;
|
||||
int turns = 0;
|
||||
|
||||
while (p1.size() > 0 && p2.size() > 0) {
|
||||
cerr << "Turn " << turns << ": " << p1.size() << " (" << stack1.size() << ") vs " << p2.size() << " (" << stack2.size() << ")" << endl;
|
||||
|
||||
int first1 = p1.front(); p1.pop_front();
|
||||
int first2 = p2.front(); p2.pop_front();
|
||||
|
||||
if (first1 > first2) {
|
||||
cerr << first1 << " > " << first2 << endl;
|
||||
moveCards(p1, first1, stack1, first2, stack2);
|
||||
turns++;
|
||||
} else if (first1 < first2) {
|
||||
cerr << first1 << " < " << first2 << endl;
|
||||
moveCards(p2, first1, stack1, first2, stack2);
|
||||
turns++;
|
||||
} else {
|
||||
// BATTLE
|
||||
cerr << "Battle" << endl;
|
||||
battleMove(stack1, first1, p1);
|
||||
battleMove(stack2, first2, p2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cerr << "END Turn " << turns << ": " << p1.size() << " (" << stack1.size() << ") vs " << p2.size() << " (" << stack2.size() << ")" << endl;
|
||||
|
||||
return turns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-generated code below aims at helping you parse
|
||||
* the standard input according to the problem statement.
|
||||
**/
|
||||
int main()
|
||||
{
|
||||
list<int> player1;
|
||||
list<int> player2;
|
||||
|
||||
int n; // the number of cards for player 1
|
||||
cin >> n; cin.ignore();
|
||||
for (int i = 0; i < n; i++) {
|
||||
string cardp1; // the n cards of player 1
|
||||
cin >> cardp1; cin.ignore();
|
||||
player1.push_back(parseCard(cardp1));
|
||||
}
|
||||
|
||||
int m; // the number of cards for player 2
|
||||
cin >> m; cin.ignore();
|
||||
for (int i = 0; i < m; i++) {
|
||||
string cardp2; // the m cards of player 2
|
||||
cin >> cardp2; cin.ignore();
|
||||
player2.push_back(parseCard(cardp2));
|
||||
}
|
||||
|
||||
int turns = runSimulation(player1, player2);
|
||||
|
||||
if (!player1.size() && !player2.size()) {
|
||||
cout << "PAT" << endl;
|
||||
} else {
|
||||
int winner = (player1.size() > 0 ? 1 : 2);
|
||||
cout << winner << " " << turns << endl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user