fork download
  1.  
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include <time.h>
  5.  
  6. void random(int *broad[4][4]) {
  7. int finish = 1,x,y;
  8. srand(time(NULL));
  9. while (finish)
  10. {
  11.  
  12. x = rand() % 4;
  13. y = rand() % 4;
  14. if (broad[x][y] == 0) {
  15. broad[x][y] = 2;
  16. break;
  17. }
  18.  
  19.  
  20. }
  21.  
  22.  
  23. }
  24. void updata_broad(int broad[4][4]) {
  25. system("cls");
  26. for (int i = 0; i < 4; i++) {
  27. for (int j = 0; j < 4; j++)
  28. printf("%d ", broad[i][j]);
  29. printf("\n");
  30. }
  31. }
  32. int main() {
  33. int broad[4][4], gameset = 1;
  34. char move[1];
  35. printf("遊戲說明 輸入w(上)s(下)a(左)d(右)\n");
  36. for (int i = 0; i < 4; i++) // 初始化遊戲盤
  37. for (int j = 0; j < 4; j++)
  38. broad[i][j] = 0;
  39. while (gameset) {
  40.  
  41. //gameset = 0;
  42. scanf("%s", move);
  43. random(&broad);
  44. updata_broad(broad);
  45. }
  46. }
Time limit exceeded #stdin #stdout #stderr 5s 2172KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found