#include <windows.h>
#include <vector>
#include <cfloat>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <cassert>
#include <random>
#include <queue>
#include <list>
#include <map>
#include <array>
#include <chrono>
#include <fstream>
#include <functional>
using namespace std;
#define ROW 5//縦
#define COL 6//横
unsigned int rnd(int mini, int maxi);//整数乱数
double d_rnd(double mini, double maxi);//実数乱数
void show_field();//盤面表示関数
void init();//初期配置生成関数
void set();//空マスを埋める関数
void fall();//ドロップの落下処理関数
int field[ROW][COL];//盤面
void fall(){
int i,j;
for(i=ROW-1;i>=0;i--){
for(j=0;j<COL;j++){
int check=i;
while(1){
if(check==ROW-1){break;}//底に到達
if(field[check+1][j]==0){//下が空マスだったら
field[check+1][j]=field[check][j];//落ちる
field[check][j]=0;//落ちると、上が空マスになる。
}
check++;
}
}
}
}
void init(){
int i,j;
for(i=0;i<ROW;i++){
for(j=0;j<COL;j++){
field[i][j]=rnd(0,6);//0-6の整数乱数
}
}
}
void set(){
int i,j;
for(i=0;i<ROW;i++){
for(j=0;j<COL;j++){
if(field[i][j]==0){//空マスだったらうめる
field[i][j]=rnd(1,6);//1-6の整数乱数
}
}
}
}
void show_field(){
int i,j;
for(i=0;i<ROW;i++){
for(j=0;j<COL;j++){
printf("%d",field[i][j]);
}
printf("\n");
}
}
unsigned int rnd(int mini, int maxi) {//xorshift整数乱数、おまじない
static unsigned int x = 123456789;
static unsigned int y = 362436069;
static unsigned int z = 521288629;
static unsigned int w = time(NULL) % INT_MAX;
unsigned int t;
t = x ^ (x << 11);
x = y; y = z; z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
return (w / (UINT_MAX / ((maxi - mini) + 1))) + mini;
}
double d_rnd(double mini, double maxi) {//xorshift実数乱数、おまじない
static unsigned int x = 123456789;
static unsigned int y = 362436069;
static unsigned int z = 521288629;
static unsigned int w = time(NULL) % INT_MAX;
unsigned int t;
t = x ^ (x << 11);
x = y; y = z; z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
return (((double)w / ((double)UINT_MAX + 1)) * (maxi - mini)) + mini;
}
int main(){
//field配列は数学と違って、下にいくほどy座標は大きくなる。右にいくほどx座標は大きくなる
int i;
for(i=0;i<5;i++){
init();
printf("problem%d,初期配置\n",i);
show_field();
fall();
printf("problem%d,落下処理後\n",i);
show_field();
set();
printf("problem%d,空マスをうめた後\n",i);
show_field();
}
return 0;
}
CiNpbmNsdWRlIDx3aW5kb3dzLmg+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxjZmxvYXQ+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxjc3RyaW5nPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGNzdGRpbnQ+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxjYXNzZXJ0PgojaW5jbHVkZSA8cmFuZG9tPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxsaXN0PgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8YXJyYXk+CiNpbmNsdWRlIDxjaHJvbm8+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIFJPVyA1Ly/nuKYKI2RlZmluZSBDT0wgNi8v5qiqCgp1bnNpZ25lZCBpbnQgcm5kKGludCBtaW5pLCBpbnQgbWF4aSk7Ly/mlbTmlbDkubHmlbAKZG91YmxlIGRfcm5kKGRvdWJsZSBtaW5pLCBkb3VibGUgbWF4aSk7Ly/lrp/mlbDkubHmlbAKdm9pZCBzaG93X2ZpZWxkKCk7Ly/nm6TpnaLooajnpLrplq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