Скачиваний:
27
Добавлен:
11.02.2016
Размер:
1.53 Кб
Скачать
// filling.cpp: определяет точку входа для консольного приложения.
//

#include "stdafx.h"
#include <iostream>
#include <conio.h>

using namespace std;

class row{
public:
	int* values;
	int width;
	int weight;
	int first;
	void input(int w){
		this->values = new int[w];
		this->width = w;
		this->weight = 0;
		for(int i=0;i<w;i++){
			cin>>this->values[i];
			this->weight+=this->values[i];
		}
		this->first = this->weight;
	}
	void refresh(){
		this->weight = 0;
		for(int i=0;i<this->width;i++){
			this->weight+=this->values[i];
		}
	}
};

void main(){
	int h,w;
	cout<<"Rows: "; cin>>h;
	cout<<"Columns: "; cin>>w;

	row* arr = new row[h];
	for(int i=0;i<h;i++){
		arr[i].input(w);
	}
	
	bool rFlag = true;
	for(int i=0;i<h;i++){
		bool lFlag = false;
		for(int j=0;j<w;j++){
			lFlag |= arr[i].values[j];
			if(lFlag) break;
		}
		rFlag &= lFlag;
		if(!rFlag) break;
	}

	if(!rFlag){
		cout<<"There isn't filling.\n";
		getch();
		return;
	}else{
		cout<<"Filling: ";
	}

	while(true){
		int max = 0;
		for(int i=0;i<h;i++){
			if(arr[max].weight<arr[i].weight){
				max = i;
			}else if(arr[max].weight==arr[i].weight){
				if(arr[max].first>arr[i].first){
					max = i;
				}
			}
		}
		if(arr[max].weight == 0) break;
		cout<<max+1<<" ";
		for(int i=0;i<w;i++){
			if(arr[max].values[i] == 1){
				for(int j=0;j<h;j++){
					arr[j].values[i] = 0;
				}
			}	
		}
		for(int i=0;i<h;i++){
			arr[i].refresh();
		}
	}
	getch();
 }

Соседние файлы в папке filling