You are viewing a single comment's thread. Return to all comments →
C++
int soma (int linha, vector<vector<int>> &arr){ int maior = 0; if(linha > 4){ return maior; } int h1 =0, h2=0, h3=0, h4=0; for (int i = linha; i < linha + 3; i++) { for (int j = 0; j < 6; j++) { if(j < 3 && i != (linha+1)){ h1 += arr[i][j]; h2 += arr[i][j+1]; h3 += arr[i][j+2]; h4 += arr[i][j+3]; } else if (i == (linha+1)){ h1 += arr[i][j+1]; h2 += arr[i][j+2]; h3 += arr[i][j+3]; h4 += arr[i][j+4]; j = 6; } else { j = 6; } } if (i == (linha +2)){ if(h1 > h2){ maior = h1; } else { maior = h2; } if (h3 > maior){ maior = h3; } if (h4 > maior){ maior = h4; } } } return maior; } int main() { vector<vector<int>> arr(6); for (int i = 0; i < 6; i++) { arr[i].resize(6); string arr_row_temp_temp; getline(cin, arr_row_temp_temp); vector<string> arr_row_temp = split(rtrim(arr_row_temp_temp)); for (int j = 0; j < 6; j++) { int arr_row_item = stoi(arr_row_temp[j]); arr[i][j] = arr_row_item; } } int maior_temp = 0, maior = 0; maior_temp = soma(0, arr); maior = soma(1, arr); if (maior < maior_temp){ maior = maior_temp; } for(int i = 2; i < 4; i ++){ maior_temp = soma(i, arr); if (maior < maior_temp){ maior = maior_temp; } } cout << maior; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 11: 2D Arrays
You are viewing a single comment's thread. Return to all comments →
C++