华为机试:密码强度等级、百钱买百鸡问题

1.密码强度等级

题目描述

密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。

       一、密码长度:

       5 分: 小于等于4 个字符

       10 分: 5 到7 字符

       25 分: 大于等于8 个字符

       二、字母:

       0 分: 没有字母

       10 分: 全都是小(大)写字母

       20 分: 大小写混合字母

       三、数字:

       0 分: 没有数字

       10 分: 1 个数字

       20 分: 大于1 个数字

       四、符号:

       0 分: 没有符号

       10 分: 1 个符号

       25 分: 大于1 个符号

       五、奖励:

       2 分: 字母和数字

       3 分: 字母、数字和符号

       5 分: 大小写字母、数字和符号

       最后的评分标准:

       >= 90: 非常安全

       >= 80: 安全(Secure)

       >= 70: 非常强

       >= 60: 强(Strong)

       >= 50: 一般(Average)

       >= 25: 弱(Weak)

       >= 0:  非常弱

对应输出为:

  VERY_WEAK,

   WEAK,    

   AVERAGE,    

   STRONG,     

   VERY_STRONG,

   SECURE,     

   VERY_SECURE 

       请根据输入的密码字符串,进行安全评定。

       注:

       字母:a-z, A-Z

       数字:-9

       符号包含如下: (ASCII码表可以在UltraEdit的菜单view->ASCII Table查看)

       !"#$%&'()*+,-./     (ASCII码:x21~0x2F)

       :;<=>?@             (ASCII<=><=><=><=><=>码:x3A~0x40)

       [\]^_`              (ASCII码:x5B~0x60)

  {|}~                (ASCII码:x7B~0x7E)

接口描述:

 Input Param 
      String pPasswordStr:    密码,以字符串方式存放。

 Return Value
   根据规则评定的安全等级。

 public static Safelevel GetPwdSecurityLevel(String pPasswordStr)
 {
     /*在这里实现功能*/
  return null;
 }

输入描述:

输入一个string的密码

输出描述:

输出密码等级

示例1

输入

38$@NoNoNo

输出

VERY_SECURE
package date0608;
//48-57 : 0-9
//65-90 : A-Z
//97-122: a-z
import java.util.Scanner;
public class Main{
    public static void main(String []args){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            int score=0;
            String str=sc.nextLine();
            //1.密码长度
            int len=str.length();
            if(len<=4){
                score+=4;
            }else if(len>=5&&len<=7){
                score+=10;
            }else{
                score+=25;
            }
            //2.字母和数字
            int dxie=0;
            int xxie=0;
            int szi=0;
            int other=0;
            //if-else处理需要注意,有些是顺序判断,有些是并行判断
            for(int i=0;i<len;i++){
                if(str.charAt(i)>=65&&str.charAt(i)<=90){
                    //全大写判断
                    dxie++;
                }else if(str.charAt(i)>=97&&str.charAt(i)<=122){
                	//全小写判断
                    xxie++;
                }else if(str.charAt(i)>=48&&str.charAt(i)<+57){
                    //是否有数字判断
                	szi++;
                }else{
                    other++;
                }
            }
            if(dxie==len||xxie==len){
                score+=10;
            }else if((dxie>0&&dxie<len)&&(xxie>0&&xxie<len)){
                score+=20;
            }
            //判断数字
            if(szi==1){
                score+=10;
            }else if(szi>1){
                score+=20;
            }
            //判断字符
            if(other==1){
                score+=10;
            }else if(other>1){
                score+=25;
            }
            //奖励判断
            if((dxie!=0&&szi!=0)||(xxie!=0&&szi!=0)){
            	score+=2;
            }
            if((dxie!=0&&other!=0&&szi!=0)||(xxie!=0&&other!=0&&szi!=0)){
            	score+=3;
            }
            if(dxie!=0&&other!=0&&szi!=0&&xxie!=0){
            	score+=5;
            }
            //输出最后等级
            if(score>=0&&score<25){
            	System.out.println("VERY_WEAK");
            }else if(score>=25&&score<50){
            	System.out.println("WEAK");
            }else if(score>=50&&score<60){
            	System.out.println("AVERAGE");
            }else if(score>=60&&score<70){
            	System.out.println("STRONG");
            }else if(score>=70&&score<80){
            	System.out.println("VERY_STRONG");
            }else if(score>=80&&score<90){
            	System.out.println("SECURE");
            }else{
            	System.out.println("VERY_SECURE");
            }
        }
    }
}

2.百钱买百鸡问题

题目描述

公元前五世纪,我国古代数学家张丘建在《算经》一书中提出了“百鸡问题”:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?

详细描述:

接口说明

原型:

int GetResult(vector &list)

输入参数:

        无

输出参数(指针指向的内存区域保证有效):

    list  鸡翁、鸡母、鸡雏组合的列表

返回值:

     -1 失败     

     0 成功

输入描述:

输入任何一个整数,即可运行程序。

输出描述:

示例1

输入

1

输出

0 25 75
4 18 78
8 11 81
12 4 84
import java.util.Scanner;

public class Main{
	/*百钱买百鸡:刚开始只考虑到百钱了完全没考虑百鸡
	 *所有始终通不过
	*/
    public static void main(String []args){
    	Scanner sc=new Scanner(System.in);
    	while(sc.hasNext()){
    		String str=sc.nextLine();
        	boolean flag=isInt(str);
    	if(flag){
    		for(int i=0;i<=12;i++){
    			for(int j=4;j<=25;j++){
    				int n=100-i-j;//满足百鸡约束条件
    					if((n%3==0)&&(i*5+j*3+n/3)==100){
    						System.out.println(i+" "+j+" "+n);
    				}
    	    	}
        	}
        	}
    	}
    }
    //判断是否为整数的函数
    public static boolean isInt(String string){
    	try{
    		int num=Integer.valueOf(string);
    		return true;
    	}catch(Exception e){
    		return false;
    	}
    }
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值