luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/PALINZ #749

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Truy vấn xâu đối xứng - Luyện Code Online

https://luyencode.net/problem/PALINZ

zhongli2k6 commented 2 years ago

code AC C++ màu mè ai cần : https://ideone.com/B2qpBV

wind5293 commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

```cpp #include #define ll long long using namespace std; bool check(string s) { int n = s.size(); if (n == 1) return true; else { for (int i = 0; i < n / 2; i++){ if (s[i] != s[n - i - 1]) return false; } return true; } } int main() { string s; cin >> s; int m; cin >> m; int l, r; while(m--){ cin >> l >> r; string tam = s.substr(l - 1, r - l + 1); if (check(tam)) cout << "YES\n"; else cout << "NO\n"; } } ```

ketamean commented 1 year ago

Lời giải chi tiết

C++

```cpp #include #include using namespace std; int main(){ char s[5100]; std::cin >> s; std::cin.ignore(); unsigned int t; std::cin >> t; unsigned int l, r; bool flag; while (t--){ std::cin >> l >> r; l--; r--; flag = true; for (unsigned int i = l; i <= r; i++) if (s[i] != s[l - i]){ flag = false; break; } if (flag) std::cout << "YES" << std::endl; else std::cout << "NO" << std::endl; } return 0; } ```