fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int N, M;
  6. cin >> N; // jumlah DDS (pendonor)
  7. cin >> M; // jumlah desa
  8.  
  9. int jumlahPendonor[11] = {0}; // indeks 1..M, maksimal 10 desa
  10.  
  11. for (int i = 0; i < N; i++) {
  12. int kodeDesa, volume;
  13. string golonganDarah;
  14. cin >> kodeDesa >> golonganDarah >> volume;
  15.  
  16. if (kodeDesa >= 1 && kodeDesa <= M)
  17. jumlahPendonor[kodeDesa]++;
  18. }
  19.  
  20. for (int i = 1; i <= M; i++) {
  21. cout << "Desa " << i << ": " << jumlahPendonor[i] << endl;
  22. }
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5324KB
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: 3
Desa 2: 2
Desa 3: 3