Cod sursa(job #2322872)

Utilizator rares.amarandeiRares Amarandei rares.amarandei Data 18 ianuarie 2019 15:22:34
Problema Jocul Flip Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.61 kb
#include <stdlib.h>
#include <stdint.h>
#include <string>
#include <vector>
#include <iostream>
#include <unordered_map>
#include <memory>
#include <algorithm>
#include <deque>
#include <iterator>
#include <numeric>
#include <assert.h>
#include <cstdlib>
#include <sstream>
#include <fstream>

#define INPUT_PATH ""
#define OUTPUT_PATH ""

void algorithm();

int main()
{
  algorithm();
  return 0;
}
using namespace std;

////////////////////////////////////////////////////////////////////////////////
void algorithm()
{
  ifstream inputFile(INPUT_PATH "flip.in");
  ofstream outputFile(OUTPUT_PATH "flip.out");
  int nrRows; inputFile >> nrRows;
  int nrCols; inputFile >> nrCols;

  vector<vector<int>> matrix(nrRows);
  for (int row = 0; row < nrRows; ++row)
  {
    int rowSum = 0;
    for (int col = 0; col < nrCols; ++col) 
    {
      int temp; inputFile >> temp;
      matrix[row].push_back(temp);
      rowSum += temp;
    }
    if (rowSum < 0)
    {
      for (int col = 0; col < nrCols; ++col)
      {
        matrix[row][col] *= -1;
      }
    }
  }

  for (int col = 0; col < nrCols; ++col)
  {
    int colSum = 0;
    for (int row = 0; row < nrRows; ++row)
    {
      colSum += matrix[row][col];
    }
    if (colSum < 0) 
    {
      for (int row = 0; row < nrRows; ++row)
      {
        matrix[row][col] *= -1;
      }
    }
  }

  int sum = 0;
  for (int row = 0; row < nrRows; ++row)
  {
    for (int col = 0; col < nrCols; ++col)
    {
      sum += matrix[row][col];
    }
  }

  outputFile << sum;
  inputFile.close();
  outputFile.close();
}