54 lines
1.1 KiB
C
54 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#pragma gcc optimize("Ofast,inline")
|
||
|
|
||
|
void process(float input[][3], float output[][5], int n);
|
||
|
|
||
|
int main(void) {
|
||
|
int n;
|
||
|
scanf("%d", &n);
|
||
|
float saleData[n][3];
|
||
|
for (int i = 0; i < n; i++) {
|
||
|
for (int j = 0; j < 3; j++) {
|
||
|
scanf("%f", &saleData[i][j]);
|
||
|
}
|
||
|
}
|
||
|
float total[6][5] = {};
|
||
|
// Process data
|
||
|
process(saleData, total, n);
|
||
|
for (int i = 0; i < 6; i++) {
|
||
|
for (int j = 0; j < 4; j++) {
|
||
|
printf("%.1f\t", total[i][j]);
|
||
|
}
|
||
|
printf("%.1f\n", total[i][4]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void process(float input[][3], float output[][5], int n) {
|
||
|
for (int i = 0; i < n; i++) { // Note number.
|
||
|
output[(int)(input[i][1] - 1)][(int)input[i][0] - 1] += input[i][2];
|
||
|
}
|
||
|
// Calculate total for salesman
|
||
|
float sum;
|
||
|
for (int i = 0; i < 4; i++) {
|
||
|
sum = 0;
|
||
|
for (int j = 0; j < 5; j++) {
|
||
|
sum += output[j][i];
|
||
|
}
|
||
|
output[5][i] = sum;
|
||
|
}
|
||
|
// Calculate total for product
|
||
|
for (int i = 0; i < 5; i++) {
|
||
|
sum = 0;
|
||
|
for (int j = 0; j < 4; j++) {
|
||
|
sum += output[i][j];
|
||
|
}
|
||
|
output[i][4] = sum;
|
||
|
}
|
||
|
// Calculate total sum
|
||
|
sum = 0;
|
||
|
for (int i = 0; i < 5; i++) {
|
||
|
sum += output[i][4];
|
||
|
}
|
||
|
output[5][4] = sum;
|
||
|
}
|