Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
チーム数、ブロック数、乱数シード、チームid、チーム名(空白不可)
#include <iostream>
#include <random>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;
struct team {
int id;
string name;
team() {
id = 0;
name = "";
}
team(int in_id, string in_name) {
id = in_id;
name = in_name;
}
bool operator<(const team& a) const {
return id < a.id;
}
bool operator==(const team& a) const {
return id == a.id && name == a.name;
}
};
// チーム総数
int team_sum;
// ブロック数
int block;
// 乱数シード
int rand_seed;
// チーム一覧を格納する配列
vector <team> teams;
// ブロックごとのチームを格納する配列
vector < vector <team> > array_block_team;
string view(team a)
{
return (to_string(a.id) + ", " + a.name);
}
void view_block(vector <team> a, char c)
{
cout << "*** " << c << " block !start! *** " << endl;
for (int i = 0; i < a.size(); i++){
cout << view(a[i]) << endl;;
}
cout << "*** " << c << " block !end! *** " << endl << endl;;
return;
}
string game_view(team a, team b)
{
return view(a) + ", vs, " + view(b);
}
void league(vector <team> input, char c)
{
vector <team> start = input;
cout << "*** " << c << " block league !start! *** " << endl;
while (1){
for (int right = 0, left = input.size() - 1; right < left; right++, left--){
cout << game_view(input[right], input[left]) << ", ";
}
puts("");
rotate(input.begin(), input.begin() + 1, input.end() - 1);
if (start == input) break;
}
cout << "*** " << c << " block league !end! *** " << endl << endl;;
return;
}
int main(void)
{
team input;
team none(-1, "none");
cout << "チーム総数 : "; cin >> team_sum; puts("");
cout << "ブロック数 : "; cin >> block; puts("");
cout << "乱数シード : "; cin >> rand_seed; puts("");
// ブロックごとのチーム数 切り上げ
int block_team = (team_sum + (block - 1)) / block;
printf("ブロックごとのチーム数は最大で %d チーム\n", block_team);
for (int i = 0; i < team_sum; ++i){
cin >> input.id >> input.name;
teams.push_back(input);
}
cout << block_team * block << endl;
sort(teams.begin(), teams.end());
// view_all();
// shuffle(teams.begin(), teams.end(), mt19937(rand_seed));
array_block_team.resize(block);
int cnt = 0;
for (int i = 0; i < block_team * block; i++){
if (i < team_sum){
array_block_team[cnt].push_back(teams[i]);
}
else {
array_block_team[cnt].push_back(none);
}
cnt++;
cnt %= block;
}
for (int i = 0; i < 2; i++){
for (int j = 0; j < 4; j++){
cout << view(array_block_team[i][j]) << endl;
}
}
for (int i = 0; i < block; ++i){
view_block(array_block_team[i], (char)(i + 'A'));
league(array_block_team[i], (char)(i + 'A'));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment