fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int TEN = 10;
  5.  
  6. int main() {
  7. int n;
  8. cin >> n;
  9. for (int i = 0; i < n; ++i) {
  10. int x, y;
  11. cin >> x >> y;
  12. int reverse = 0;
  13. while (x) {
  14. reverse = reverse * TEN + x % TEN;
  15. x /= TEN;
  16. }
  17. while (y > 1) {
  18. reverse /= TEN;
  19. --y;
  20. }
  21. if (x < 0) {
  22. reverse *= -1;
  23. }
  24. cout << reverse % TEN << '\n';
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 5284KB
stdin
3
112 3
21 2
6789 3
stdout
2
1
8