1081 检查密码

int digit = 0; //无数字
int eng = 0; //无英文
int islegal(string s){
    digit = 0; //无数字
    eng = 0; //无英文
    for(int i = 0;i < s.length();++i){
        if( isdigit(s[i]) ) digit = 1;
        else if( isalpha(s[i]) ) eng = 1;
        else if( s[i] == '.') continue;
        else return 0; //其他非法字符,跳出
    }
    return 1;
}
int main()
{
    //freopen("D:\\文件夹\\Desktop\\use.txt","r",stdin);
    int n;scanf("%d",&n);getchar();
    for(int i = 0;i < n;++i){
        string s;
        getline(cin,s);
        if(i != 0) printf("\n");
        if(s.length() < 6) {cout<<"Your password is tai duan le.";continue;}
        if( !islegal(s) )  {cout<<"Your password is tai luan le.";continue;}
        if(eng == 1 && digit == 0) {cout<<"Your password needs shu zi.";continue;}
        if(eng == 0 && digit == 1) {cout<<"Your password needs zi mu.";continue;}
        cout<<"Your password is wan mei.";
    }
    return 0;
}

谨记谨记,字符串的输入要getline,因为存在空格

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我的PAT系列文章更新重心已移至Github,欢迎来看PAT题解的小伙伴请到Github Pages浏览最新内容。...
    OliverLew阅读 4,410评论 0 0
  • 题目 本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符...
    Jingtianer阅读 4,858评论 0 0
  • 官网 中文版本 好的网站 Content-type: text/htmlBASH Section: User ...
    不排版阅读 9,947评论 0 5
  • 一、Python简介和环境搭建以及pip的安装 4课时实验课主要内容 【Python简介】: Python 是一个...
    _小老虎_阅读 11,131评论 0 10
  • Linux指令中文说明传送入口 整理自Linux指令中文说明 文本和数据进行处理的编程语言awk 是一种编程语言,...
    释闲人阅读 6,537评论 1 6