fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. using namespace std;
  5.  
  6. void test_func(char, char);
  7.  
  8. typedef void(&func_ref)(char, char);
  9.  
  10. static map<int,func_ref> tbl = {
  11. { 'A' << 8 | 'B', test_func },
  12. { 'B' << 8 | 'Q', test_func },
  13. { 'D' << 8 | 'S', test_func },
  14. { 'E' << 8 | 'Q', test_func },
  15. { 'B' << 8 | 'W', test_func },
  16. { 'F' << 8 | 'Q', test_func },
  17. { 'B' << 8 | 'S', test_func },
  18. { 'S' << 8 | 'Q', test_func },
  19. { 'B' << 8 | 'X', test_func },
  20. { 'R' << 8 | 'R', test_func },
  21. { 'B' << 8 | 'O', test_func },
  22. { 'K' << 8 | 'Q', test_func },
  23. { 'J' << 8 | 'I', test_func }
  24. };
  25.  
  26. int main() {
  27. char a, b;
  28. while (cin >> a >> b) {
  29. auto fp = tbl.find(a << 8 | b);
  30. if (fp != tbl.end()) {
  31. fp->second(a, b);
  32. }
  33. }
  34. return 0;
  35. }
  36.  
  37. void test_func(char a, char b) {
  38. std::cout << "Voided function called: " << a << ":" << b << std::endl;
  39. }
  40.  
Success #stdin #stdout 0s 3468KB
stdin
ABDSSQBO
stdout
Voided function called: A:B
Voided function called: D:S
Voided function called: S:Q
Voided function called: B:O