Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int activeCol = 0;
  4. map<string, int> generalMap;
  5.  
  6. void doCheck(vector<vector<string>> myVector, int row, int col, int r, int c, int sum, int count) {
  7.     if(r >= row || c < 0 || c >= col)
  8.         return;
  9.     else if(myVector[r][c] == ".")
  10.         doCheck(myVector, row, col, r+1, c, sum, count);
  11.     else {
  12.         sum += stoi(myVector[r][c]) ;
  13.         count++;
  14.  
  15.         if(r == row -1) {
  16.             if(sum > generalMap["max"]) {
  17.                 generalMap["max_col"] = activeCol;
  18.                 generalMap["max"] = sum;
  19.                 generalMap["max_count"] = count;
  20.             }
  21.             if (generalMap["min"] == 0 || sum < generalMap["min"]) {
  22.                 generalMap["min_col"] = activeCol;
  23.                 generalMap["min"] = sum;
  24.                 generalMap["min_count"] = count;
  25.             }
  26.             return;
  27.         }
  28.  
  29.         doCheck(myVector, row, col, r, c-1, sum, count);
  30.         doCheck(myVector, row, col, r, c+1, sum, count);
  31.     }
  32. }
  33.  
  34. int main () {
  35.     int n, row, col;
  36.     int sum=0, count=0;
  37.  
  38.     cin >> row >> col;
  39.     vector<vector<string>> myVector(row, vector<string> (col));
  40.  
  41.     for (int r=0; r<row; r++) {
  42.         for (int c=0; c<col; c++) {
  43.             cin >> myVector[r][c];
  44.         }
  45.     }
  46.  
  47.     for (int c=0; c<col; c++) {
  48.         activeCol = c+1;
  49.         doCheck(myVector, row, col, 0, c, sum, count);
  50.     }
  51.  
  52.     cout << generalMap["max_col"] << " " << generalMap["max"] << " " << generalMap["max_count"] << " " << endl;
  53.     cout << generalMap["min_col"] << " " << generalMap["min"] << " " << generalMap["min_count"] << " " << endl;
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement