10.2学习总结

(1)今日安排
队列实现回文
(2)源代码

#include <stdio.h>
#include <queue>
#include <cstring>
#define MAXSIZE 100
using namespace std;

int main()
{
    queue <char>q;
    char a[MAXSIZE];
    scanf("%s",&a);
    int t=strlen(a);
    int sum;
    //入队
    for(int k=0;k<t;k++)
    {
        if(a[k]!=' ')
        {
            q.push(a[k]);
            sum++;
        }

    }
    //出队
    int count=0;
    for(int j=t-1;j>=0;j--)
    {
        if(a[j]!=' ')
        {
             char temp=q.front();
        if(a[j]!=temp)
        {
            count++;
        }
        q.pop();
        }

    }
    if(count==0)
    {
        printf("该字符串是回文字符串");
    }
    else
    {
         printf("该字符串不是回文字符串");
    }
    return 0;
}

 

posted @ 2021-10-02 22:37  今天又双叒叕在敲代码  阅读(18)  评论(0编辑  收藏  举报