HDU 2029 Palindromes _easy version(左右指针)

题目链接:点击这里

在这里插入图片描述
尺取法代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n--)
	{
        string s;
		cin>>s;
        bool ans = true;
        int i = 0, j = s.size()-1;  //双指针
        while(i<j)
		{
            if(s[i] != s[j])
			{
                ans = false;
                break;
            }
            i++;	 //移动双指针
			j--;              
        }
        if(ans)	cout<<"yes"<<endl;
        else	cout <<"no"<<endl;
    }
    return 0;
}
发布了703 篇原创文章 · 获赞 104 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/qq_42815188/article/details/104097992