Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int activeCol = 0;
- map<string, int> generalMap;
- void doCheck(vector<vector<string>> myVector, int row, int col, int r, int c, int sum, int count) {
- if(r >= row || c < 0 || c >= col)
- return;
- else if(myVector[r][c] == ".")
- doCheck(myVector, row, col, r+1, c, sum, count);
- else {
- sum += stoi(myVector[r][c]) ;
- count++;
- if(r == row -1) {
- if(sum > generalMap["max"]) {
- generalMap["max_col"] = activeCol;
- generalMap["max"] = sum;
- generalMap["max_count"] = count;
- }
- if (generalMap["min"] == 0 || sum < generalMap["min"]) {
- generalMap["min_col"] = activeCol;
- generalMap["min"] = sum;
- generalMap["min_count"] = count;
- }
- return;
- }
- doCheck(myVector, row, col, r, c-1, sum, count);
- doCheck(myVector, row, col, r, c+1, sum, count);
- }
- }
- int main () {
- int n, row, col;
- int sum=0, count=0;
- cin >> row >> col;
- vector<vector<string>> myVector(row, vector<string> (col));
- for (int r=0; r<row; r++) {
- for (int c=0; c<col; c++) {
- cin >> myVector[r][c];
- }
- }
- for (int c=0; c<col; c++) {
- activeCol = c+1;
- doCheck(myVector, row, col, 0, c, sum, count);
- }
- cout << generalMap["max_col"] << " " << generalMap["max"] << " " << generalMap["max_count"] << " " << endl;
- cout << generalMap["min_col"] << " " << generalMap["min"] << " " << generalMap["min_count"] << " " << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement