fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. string DaoNguoc(string s) {
  4. int length = s.length();
  5. string temp;
  6. for (int i = length-1; i >=0; i--) {
  7. temp.push_back(s[i]);
  8. }
  9. return temp;
  10. }
  11. int main()
  12. {
  13. int a,b;
  14. string s;cin >>s;
  15. int n;cin >>n;
  16. for(int i = 1 ; i<= n;i++)
  17. {
  18. cin >>a>>b;
  19. if(s.substr(a-1,b-a+1) == DaoNguoc(s.substr(a-1,b-a+1)))
  20. {
  21. cout<<"YES\n";
  22. }
  23. else
  24. {
  25. cout<<"NO\n";
  26. }
  27. }
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 5524KB
stdin
00001
11
1 4
3 5
3 4
5 5
2 5
4 5
1 4
5 5
2 5
1 5
2 4
stdout
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES