码迷,mamicode.com
首页 > 其他好文 > 详细

俄罗斯方块60分

时间:2017-08-16 00:07:49      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:pac   highlight   str   iostream   include   out   stream   cout   break   

#include<iostream>
using namespace std;
int main() {
	int a[15][10];
	int b[5][5];
	int height[4] = { 0,0,0,0 };
	int leftmargin;
	int max = 15;
	int i, j, k;
	int tmp;
	int x, y;
	bool flag;
	for (i = 0; i<15; i++)
		for (j = 0; j<10; j++)
			cin >> a[i][j];
	leftmargin = 3;
	for (i = 0; i<4; i++) {
		for (j = 0; j<4; j++) {
			cin >> b[i][j];
			if (b[i][j] == 1 && j < leftmargin)
				leftmargin = j;
		}
	}
	cin >> x;
	y = 0;
	for (i = 0; i < 4; i++) {
		if (x >= leftmargin) {
			for (j = x - leftmargin; j < x - leftmargin + 4; j++)
				a[i][j] = b[i][j - x + leftmargin];
		}
		else {
			for (j = x; j < x - leftmargin + 4; j++)
				a[i][j] = b[i][j - x + leftmargin];
		}
	}
	for (j = x; j < x + 4; j++) {
		flag = false;
		for (i = 0; i < 15; i++) {
			if (a[i][j] == 1 && a[i+1][j] == 0 && i < 4) {
				flag = true;
			}
			else if (a[i][j] == 0 && flag == true) {
				height[j - x]++;
			}
			else if (a[i][j] == 1 && i >= 4)
				break;
		}
	}
	for (i = 0; i < 4; i++) {
		if (height[i] < max && height[i] != 0)
			max = height[i];
	}
	for (i = 0; i < 4; i++)
		for (j = 0; j < 10; j++)
			a[i][j] = 0;
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			if (b[i][j] != 0)
				a[i + max][j + x - leftmargin] = b[i][j];
		}
	}
	for (i = 0; i < 15; i++) {
		for (j = 0; j < 10; j++) {
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

  

俄罗斯方块60分

标签:pac   highlight   str   iostream   include   out   stream   cout   break   

原文地址:http://www.cnblogs.com/fishegg/p/7368403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!