zoukankan      html  css  js  c++  java
  • 做题记录--day46

    《算法笔记》3.6小节——入门模拟->字符串处理

    例题I 回文串没有难度,从[0到len/2-1]就可以

    #include<stdio.h>
    #include<string.h>
    bool pd(char a[])
    {
        int len=strlen(a);
        if(len==0||len==1) return true;
        for(int i=0;i<=len/2-1;i++)
        {
            if(a[i]!=a[len-i-1])
                return false;
        }
        return true;
    }
    int main()
    {
        char a[1000];
        while(scanf("%s",a)!=EOF)
        {
            bool ans=pd(a);
            if(ans==true)
                printf("YES
    ");
            else
                printf("NO
    ");
        }
        return 0;
    }
    View Code

     PAT B1009

    题本身没有什么难度,但是需要注意,不能直接在scanf("%s",&temp[len++])!=EOF这么写,因为这样的话最后一次等于EOF里面也会实现len++(因为前面的语句成功执行了),还有就是%s会自动跳过空格和回车,写不写getchar没什么区别

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char temp[100][100];
        int len=0;
        while(scanf("%s",&temp[len])!=EOF)
        {
            len++;
            getchar();
        }
        for(int i=len-1;i>0;i--)
        {
            printf("%s",temp[i]);
            printf(" ");
        }
        printf("%s",temp[0]);
        return 0;
    }
    View Code
    时间才能证明一切,选好了就尽力去做吧!
  • 相关阅读:
    mongodb nodemailer
    mongodb session
    mongodb cookie
    mongodb multer
    mongodb operate update and delete
    mongodb find opearate
    echart
    Git学习
    PHP海补知识(11)-- 自定义exception
    ThinkPHP U方法
  • 原文地址:https://www.cnblogs.com/tingxilin/p/11398526.html
Copyright © 2011-2022 走看看