Pagini recente » Cod sursa (job #1416837) | Cod sursa (job #2682171) | Cod sursa (job #2673736) | Cod sursa (job #952859) | Cod sursa (job #2634542)
#include <fstream>
using namespace std;
ifstream in("flip.in");
ofstream out("flip.out");
int table[16][16];
int x,y;
bool ChangedLines = true;
bool ChangedColomns = true;
void CheckLines(){
for(int i = 0;i < x;i++){
int sum = 0;
for(int j = 0;j < y;j++){
sum += table[i][j];
}
if(sum < 0){
for(int j = 0;j < y;j++){
table[i][j] *= -1;
}
ChangedLines = true;
}
}
}
void CheckColons(){
for(int i = 0;i < y;i++){
int sum = 0;
for(int j = 0;j < x;j++){
sum += table[j][i];
}
if(sum < 0){
for(int j = 0;j < x;j++){
table[j][i] *= -1;
}
ChangedColomns = true;
}
}
}
int main(){
in >> x >> y;
for(int i = 0;i < x;i++)
for(int j = 0;j < y;j++){
int a;
in >> a;
table[i][j] = a;
}
while(ChangedColomns || ChangedLines){
CheckColons();
CheckLines();
ChangedColomns = false;
ChangedLines = false;
}
int sum = 0;
for(int i = 0;i < x;i++)
for(int j = 0;j < y;j++)
sum += table[i][j];
out << sum;
return 0;
}