fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, jumlahDesa;
  7. cin >> n >> jumlahDesa;
  8.  
  9. int desa, gol;
  10. double volume;
  11.  
  12. // [desa][golongan]
  13. int jumlahPendonor[100][5] = {0};
  14. double totalVolume[100][5] = {0};
  15.  
  16. for (int i = 0; i < n; i++) {
  17. cin >> desa >> gol >> volume;
  18. // validasi agar tidak keluar dari batas
  19. if (desa >= 1 && desa <= jumlahDesa && gol >= 1 && gol <= 4) {
  20. jumlahPendonor[desa][gol]++;
  21. totalVolume[desa][gol] += volume;
  22. }
  23. }
  24.  
  25. for (int i = 1; i <= jumlahDesa; i++) {
  26. cout << "Desa " << i << ":" << endl;
  27. cout << "A:" << jumlahPendonor[i][1] << " " << totalVolume[i][1] << endl;
  28. cout << "B:" << jumlahPendonor[i][2] << " " << totalVolume[i][2] << endl;
  29. cout << "AB:" << jumlahPendonor[i][3] << " " << totalVolume[i][3] << endl;
  30. cout << "O:" << jumlahPendonor[i][4] << " " << totalVolume[i][4] << endl;
  31. }
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5312KB
stdin
8
3
3 1 150
1 2 250
3 1 300
1 3 450
2 2 200
3 4 350
1 4 500
2 1 500
stdout
Desa 1:
A:0 0
B:1 250
AB:1 450
O:1 500
Desa 2:
A:1 500
B:1 200
AB:0 0
O:0 0
Desa 3:
A:2 450
B:0 0
AB:0 0
O:1 350