【牛客】HJ87 密码强度等级 CM62 井字棋

题目一:密码强度等级

题目链接:密码强度等级_牛客题霸_牛客网 (nowcoder.com)

本题主要考察C语言中逻辑分支语句,基本语句以及对各种特殊字符 ,ASCII值以及条件表达中的逻辑运算符关系运算符各自功能的理解,以及基本使用,根据不同的条件,进入不同的分支,统计求和

解题思路:

1、先统计大小写字母,数字,以及特殊字符的个数

2、再对题目给的限定条件累加求和

代码实现:

#include<iostream>
using namespace std;

int string_count( const string& str)
{
        int digit=0,symbol=0;
        int lower=0,upper=0,character=0;
        int sum=0;
        for(auto ch:str)
        {
             
            if(ch>='a'&&ch<='z')
            {
              lower++;
              character++;
            }
            else if(ch>='A'&&ch<='Z')
            {
                upper++;
                character++;
            }
            else if(ch>='0'&&ch<='9')
            digit++;

            if((ch>=0x21&&ch<=0x2F)||
            (ch>=0x3A&&ch<=0x40)||
            (ch>=0x5B&&ch<=0x60)||
            (ch>=0x7B&&ch<=0x7E))
            symbol++;
        }

            //str字符长度分数
                if(str.size()>=8)
                sum+=25;
                else if (str.size()>=5&&str.size()<=7)
                sum+=10;
                else if (str.size()<=4)
                sum+=5;

        //计算字母分数
           if(lower>0&&upper>0)
           sum+=20;
           else if (lower==character||upper==character)
           sum+=10;

            //计算数字分数
                if(digit>1)
                sum+=20;
                else if (digit==1)
                    sum+=10;

            //计算字符分数
                if(symbol>1)
                sum+=25;
                else if (symbol==1)
                sum+=10;
            
            if(lower>0&&upper>0&&digit>0&&symbol>0)
            sum+=5;
            else if((lower>0||upper>0)&&digit>0&&symbol>0)
            sum+=3;
            else if((lower>0||upper>0)&&digit>0&&symbol==0)
                sum+=2;

            return sum;
}
int main()
{
    string str;
    while(cin>>str)
    {
        int score=string_count(str);
        if(score>=90){
            cout<<"VERY_SECURE"<<endl;
        }
        else if(score>=80){
            cout<<"SECURE"<<endl;
        }
        else if(score>=70) {
            cout<<"VERY_STRONG"<<endl;
        }
        else if(score>=60) {
            cout<<"STRONG"<<endl;
        }
        else if(score>=50) {
            cout<<"AVERAGE"<<endl;
        }
        else if(score>=25) {
            cout<<"WEAK"<<endl;
        }
        else if(score>=0) {
            cout<<"VERY_WEAK"<<endl;
        }
    }
}

题目二:井字棋

题目链接:井字棋_牛客题霸_牛客网 (nowcoder.com)

题目描述:

解题思路:

玩家棋子为1

整个一行相加结果为列数 就获胜了

整个一列相加结果为行数 就获胜了

正斜 board[row][row]

副斜board[row][col-1-i]

 代码实现:

class Board {
public:
    bool checkWon(vector<vector<int> > board) {
        // write code here
        int row=board.size();
        int col=board[0].size();

        //行连成排
        for(int i=0;i<row;i++)
        {
            int sum=0;
            for(int j=0;j<col;j++)
            {
                sum+=board[i][j];
            }
            if(sum==col) return true;
        }
        //列连成排
        for(int i=0;i<col;i++)
        {
            int sum=0;
            for(int j=0;j<row;j++)
            {
                sum+=board[j][i];
            }
            if(sum==row) return true;
        }
        //正斜成排
        int sum=0;
        for(int i=0;i<row;i++)
        {
            sum+=board[i][i];
        }
        if(sum==row)  return true;
        //副斜成排
        sum=0;
        for(int i=0;i<row;i++)
        {
            sum+=board[i][col-1-i];
        }
        if(sum==row) return true;

        return false;
    }
};

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值