/* * 测试HashMap的应用,判断 */import java.util.HashMap;public class HuaWeiTest { private static final Integer ONE = new Integer(1); public static void main(String[] args) { HashMapm=new HashMap (); char c[]={'张','张','王','王','王','赵','刘'}; for(int i=0;i
测试结果:
不同姓氏有4个
{张=2, 赵=1, 刘=1, 王=3}
华为机试题目:
package huawei7;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Scanner;public class Password { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Listlist = new ArrayList (); while(sc.hasNext()) { list.add(sc.nextLine()); } for(int i=0;i hash = new HashMap (); for(int i=0;i ='0' && ch<='9') { hash.put("num", 1); } else if(ch>='a' && ch<='z') { hash.put("upCase", 1); } else if(ch>='A' && ch<='Z') { hash.put("lowCase", 1); } else if((ch>=0x21 && ch<=0x2F) || (ch>=0x3A && ch<=0x40) ||(ch>=0x5B && ch<=0x60) ||(ch>=0x7B && ch<=0x7E)) { hash.put("symbol", 1); } } Iterator ite = hash.values().iterator(); int count =0; while(ite.hasNext()) { count+=ite.next(); } if(count<3) { return false; } for(int i=0;i
华为漂亮度
package huawei4;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Scanner;public class Beautiful { private static final Integer ONE = new Integer(1); public static void main(String[] args){ System.out.println("请输入样例:"); Scanner scStr=new Scanner(System.in); String in=scStr.nextLine(); String str[]=in.split(" "); //存起来,空格分割; HashMaphash=new HashMap (); int count=str.length-1; //因为空格数为2的时候,时间字符串长度为3,而那个字符串也是两个 //ArrayList list=new ArrayList (); StringBuffer string1=new StringBuffer(); for(int i=0;i