fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void swapping_handphones(int N, char handphones[N][11], int M, char mappings[M][2][11]) {
  5. // Lakukan swapping berdasarkan mapping
  6. for (int i = 0; i < N; i++) {
  7. for (int j = 0; j < M; j++) {
  8. if (strcmp(handphones[i], mappings[j][0]) == 0) {
  9. strcpy(handphones[i], mappings[j][1]);
  10. break;
  11. } else if (strcmp(handphones[i], mappings[j][1]) == 0) {
  12. strcpy(handphones[i], mappings[j][0]);
  13. break;
  14. }
  15. }
  16. }
  17. }
  18.  
  19. int main() {
  20. // Input
  21. int N;
  22. scanf("%d", &N);
  23. char handphones[N][11];
  24. for (int i = 0; i < N; i++) {
  25. scanf("%s", handphones[i]);
  26. }
  27.  
  28. int M;
  29. scanf("%d", &M);
  30. char mappings[M][2][11];
  31. for (int i = 0; i < M; i++) {
  32. scanf("%s %s", mappings[i][0], mappings[i][1]);
  33. }
  34.  
  35. // Output
  36. swapping_handphones(N, handphones, M, mappings);
  37. for (int i = 0; i < N; i++) {
  38. printf("%s\n", handphones[i]);
  39. }
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 5300KB
stdin
5
vivo
oppo
realme
xiaomi
huawei
2
vivo realme
huawei vivo
stdout
realme
oppo
vivo
xiaomi
vivo