fork(1) download
  1.  
  2. #include <windows.h>
  3. #include <vector>
  4. #include <cfloat>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <ctime>
  8. #include <cstdlib>
  9. #include <cmath>
  10. #include <string>
  11. #include <iostream>
  12. #include <cstdint>
  13. #include <algorithm>
  14. #include <cassert>
  15. #include <random>
  16. #include <queue>
  17. #include <list>
  18. #include <map>
  19. #include <array>
  20. #include <chrono>
  21. #include <fstream>
  22. #include <functional>
  23.  
  24. using namespace std;
  25.  
  26. #define ROW 5//縦
  27. #define COL 6//横
  28.  
  29. unsigned int rnd(int mini, int maxi);//整数乱数
  30. double d_rnd(double mini, double maxi);//実数乱数
  31. void show_field();//盤面表示関数
  32. void init();//初期配置生成関数
  33. void set();//空マスを埋める関数
  34. void fall();//ドロップの落下処理関数
  35.  
  36. int field[ROW][COL];//盤面
  37.  
  38.  
  39. void fall(){
  40. int i,j;
  41.  
  42. for(i=ROW-1;i>=0;i--){
  43. for(j=0;j<COL;j++){
  44. int check=i;
  45. while(1){
  46. if(check==ROW-1){break;}//底に到達
  47. if(field[check+1][j]==0){//下が空マスだったら
  48. field[check+1][j]=field[check][j];//落ちる
  49. field[check][j]=0;//落ちると、上が空マスになる。
  50. }
  51. check++;
  52. }
  53. }
  54. }
  55. }
  56.  
  57. void init(){
  58. int i,j;
  59.  
  60. for(i=0;i<ROW;i++){
  61. for(j=0;j<COL;j++){
  62. field[i][j]=rnd(0,6);//0-6の整数乱数
  63. }
  64. }
  65. }
  66. void set(){
  67. int i,j;
  68.  
  69. for(i=0;i<ROW;i++){
  70. for(j=0;j<COL;j++){
  71. if(field[i][j]==0){//空マスだったらうめる
  72. field[i][j]=rnd(1,6);//1-6の整数乱数
  73. }
  74. }
  75. }
  76. }
  77.  
  78. void show_field(){
  79. int i,j;
  80.  
  81. for(i=0;i<ROW;i++){
  82. for(j=0;j<COL;j++){
  83. printf("%d",field[i][j]);
  84. }
  85. printf("\n");
  86. }
  87.  
  88. }
  89.  
  90. unsigned int rnd(int mini, int maxi) {//xorshift整数乱数、おまじない
  91. static unsigned int x = 123456789;
  92. static unsigned int y = 362436069;
  93. static unsigned int z = 521288629;
  94. static unsigned int w = time(NULL) % INT_MAX;
  95. unsigned int t;
  96.  
  97. t = x ^ (x << 11);
  98. x = y; y = z; z = w;
  99. w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
  100.  
  101. return (w / (UINT_MAX / ((maxi - mini) + 1))) + mini;
  102.  
  103. }
  104. double d_rnd(double mini, double maxi) {//xorshift実数乱数、おまじない
  105. static unsigned int x = 123456789;
  106. static unsigned int y = 362436069;
  107. static unsigned int z = 521288629;
  108. static unsigned int w = time(NULL) % INT_MAX;
  109. unsigned int t;
  110.  
  111. t = x ^ (x << 11);
  112. x = y; y = z; z = w;
  113. w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
  114.  
  115. return (((double)w / ((double)UINT_MAX + 1)) * (maxi - mini)) + mini;
  116.  
  117. }
  118.  
  119.  
  120. int main(){
  121.  
  122. //field配列は数学と違って、下にいくほどy座標は大きくなる。右にいくほどx座標は大きくなる
  123.  
  124. int i;
  125.  
  126. for(i=0;i<5;i++){
  127. init();
  128. printf("problem%d,初期配置\n",i);
  129. show_field();
  130. fall();
  131. printf("problem%d,落下処理後\n",i);
  132. show_field();
  133. set();
  134. printf("problem%d,空マスをうめた後\n",i);
  135. show_field();
  136. }
  137.  
  138. return 0;
  139. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:21: fatal error: windows.h: No such file or directory
 #include <windows.h>
                     ^
compilation terminated.
stdout
Standard output is empty