标签:fun nan tput string 分析 end output 数据规模 相加
时间限制:1000MS内存限制:65536KB
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 int map[5][5],flag[5][5]; 5 int fun() 6 { 7 for (int i=1;i<=4;i++) 8 for (int j=1;j<=4;j++) 9 if (map[i][j]==0) 10 return 1; 11 return 0; 12 } 13 int main () 14 { 15 int n,a,b,c; 16 char f; 17 cin>>n; 18 for (int i=1;i<=n;i++) 19 { 20 cin>>a>>b>>c>>f; 21 if (fun()==0)z 22 { 23 cout<<"Game over!"; 24 return 0; 25 } 26 map[a][b]=c; 27 if (f==‘L‘) 28 { 29 memset(flag,0,sizeof(flag)); 30 for (int i=1;i<=4;i++) 31 for (int j=1;j<=4;j++) 32 { 33 if (map[i][j]==0) 34 continue; 35 int wz=j; 36 for (int k=j-1;k>=1;k--) 37 { 38 if (map[i][k]==map[i][wz]&&flag[i][k]==0) 39 { 40 flag[i][k]=1; 41 map[i][k]=map[i][wz]*2; 42 map[i][wz]=0; 43 break; 44 } 45 if (map[i][k]==0) 46 { 47 int t=map[i][wz]; 48 map[i][wz]=0; 49 map[i][k]=t; 50 wz=k; 51 continue; 52 } 53 break; 54 } 55 } 56 } 57 if (f==‘R‘) 58 { 59 memset(flag,0,sizeof(flag)); 60 for (int i=1;i<=4;i++) 61 for (int j=4;j>=1;j--) 62 { 63 if (map[i][j]==0) 64 continue; 65 int wz=j; 66 for (int k=j+1;k<=4;k++) 67 { 68 if (map[i][k]==map[i][wz]&&flag[i][k]==0) 69 { 70 flag[i][k]=1; 71 map[i][k]=map[i][wz]*2; 72 map[i][wz]=0; 73 break; 74 } 75 if (map[i][k]==0) 76 { 77 int t=map[i][wz]; 78 map[i][wz]=0; 79 map[i][k]=t; 80 wz=k; 81 continue; 82 } 83 break; 84 } 85 } 86 } 87 if (f==‘U‘) 88 { 89 memset(flag,0,sizeof(flag)); 90 for (int i=1;i<=4;i++) 91 for (int j=1;j<=4;j++) 92 { 93 if (map[i][j]==0) 94 continue; 95 int wz=i; 96 for (int k=i-1;k>=1;k--) 97 { 98 if (map[wz][j]==map[k][j]&&flag[k][j]==0) 99 { 100 flag[k][j]=1; 101 map[k][j]=map[wz][j]*2; 102 map[wz][j]=0; 103 break; 104 } 105 if (map[k][j]==0) 106 { 107 int t=map[wz][j]; 108 map[wz][j]=0; 109 map[k][j]=t; 110 wz=k; 111 continue; 112 } 113 break; 114 } 115 } 116 } 117 if (f==‘D‘) 118 { 119 memset(flag,0,sizeof(flag)); 120 for (int i=4;i>=1;i--) 121 for (int j=4;j>=1;j--) 122 { 123 if (map[i][j]==0) 124 continue; 125 int wz=i; 126 for (int k=i+1;k<=4;k++) 127 { 128 if (map[wz][j]==map[k][j]&&flag[k][j]==0) 129 { 130 flag[k][j]=1; 131 map[k][j]=map[wz][j]*2; 132 map[wz][j]=0; 133 break; 134 } 135 if (map[k][j]==0) 136 { 137 int t=map[wz][j]; 138 map[wz][j]=0; 139 map[k][j]=t; 140 wz=k; 141 continue; 142 } 143 break; 144 } 145 } 146 } 147 } 148 for (int i=1;i<=4;i++) 149 { 150 cout<<map[i][1]<<" "<<map[i][2]<<" "<<map[i][3]<<" "<<map[i][4]; 151 cout<<endl; 152 } 153 }
标签:fun nan tput string 分析 end output 数据规模 相加
原文地址:https://www.cnblogs.com/zjzjzj/p/9746552.html