Cod sursa(job #561413)

Utilizator Alexxino7Alexandru Popescu Alexxino7 Data 20 martie 2011 12:05:54
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<iostream>
#include<fstream>
using namespace std;
#define DIM 20

int main(){
	int neg=0,T[DIM][DIM],i,k,j,N,M,val,S=0,sl=0;
	ifstream fin("flip.in");
	ofstream fout("flip.out");
	fin>>N>>M;
	do{
		neg=0;
		for(i=0;i<N;i++){
			for(j=0,sl=0;j<M;j++){
				fin>>val;
				T[i][j]=val;
				sl+=val;
			}
			if(sl<0)
				for(sl=0,j=M-1;j>=0;j--){
					T[i][j]=-T[i][j];
					neg++;
				}
		}
		cout<<endl;
		for(S=0,i=0;i<M;i++){
			for(S=0,sl=0,j=0;j<N;j++){
				sl+=T[j][i];
				cout<<sl<<" ";
				S+=sl;
			}
			if(sl<0){
				neg++;
				for(k=j,k=N-1;k>=0;k--){
					T[k][i]=-T[k][i];
				}
			}
		}
	}
	while(neg!=0);
	fout<<S;
	fin.close();
	fout.close();
	return 0;
}