1011
Maximum element and its index from each row of a 2-D array.
1 Key Points
int arr[3][3];
int index = max_element(arr[i], arr[i] + 3) - arr[i];
int value = *max_element(arr[i], arr[i] + 3);
2 Answers
#include <cctype>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double arr[3][3];
int main() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> arr[i][j];
}
}
/*
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
// */
// (4.1×3.1×2.5×65%−1)×2
double ans = 1;
for (int i = 0; i < 3; i++) {
int index = max_element(arr[i], arr[i] + 3) - arr[i];
switch (index)
{
case 0:
cout << "W ";
break;
case 1:
cout << "T ";
break;
case 2:
cout << "L ";
break;
default:
break;
}
double val = *max_element(arr[i], arr[i] + 3);
// cout << m << endl;
ans *= val;
}
ans = (ans * 0.65 - 1) * 2;
// cout << ans << endl;
printf("%.2lf", ans);
return 0;
}
/*
Sample Input:
1.1 2.5 1.7
1.2 3.1 1.6
4.1 1.2 1.1
Sample Output:
T T W 39.31
*/