第一题是匹配单词,有数字,符号,大写字母,小写字母四种类型,还有特定长度为8到120,四个符号都有且长度满足则输出0,若长度不满足则输出1,若没完全包含四个符号则输出2;
过了83%还有一个用例不知道怎么过,
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(in.hasNext()){ String s=in.next(); char[] ch=s.toCharArray(); int length=ch.length; if(length<8||length>120){ System.out.println(1); continue; } int num=0; int bigwrite=0; int smallwrite=0; int zifu=0; for(int i=0;i<ch.length;i++){ if(ch[i]>='0'||ch[i]<='9'){ num++; } if(ch[i]>='a'||ch[i]<='z'){ smallwrite++; } if (ch[i]>='A'||ch[i]<='Z'){ bigwrite++; } if(ch[i]=='!'&&ch[i]=='#'&&ch[i]=='$'){ zifu++; } } if(num>0&&bigwrite>0&&smallwrite>0&&zifu>0){ System.out.println(0); } else{ System.out.println(2); } } } }好了,直接看第二题没有网格看了十分钟,没时间了,直接骗了50%,输出个true;转去携程辽
携程选择比小米难一点,编程也难
1.过了77%,逗号不知如何去掉,搞了半天
import java.util.HashMap; import java.util.Scanner; import java.util.Map; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); String target=in.nextLine(); String ischeck=in.nextLine(); String instead=in.nextLine(); StringBuilder sb = new StringBuilder(); String[] strings = ischeck.split(" "); Map<Character, Integer> map1 = new HashMap<Character, Integer>(); for (int k = 0; k < target.length(); k++) { if (!map1.containsKey(target.charAt(k))) { map1.put(target.charAt(k), 1); } else { map1.put(target.charAt(k), map1.get(target.charAt(k)) + 1); } } for (int i = 0; i < strings.length; i++) { char[] ch = strings[i].toCharArray(); Map<Character, Integer> map = new HashMap<Character, Integer>(); int j; for ( j = 0; j < ch.length; j++) { if (!map.containsKey(ch[j])) { map.put(ch[j], 1); } else { map.put(ch[j], map.get(ch[j]) + 1); } } if (map.equals(map1)) { strings[i] = instead; } sb.append(strings[i] + " "); } System.out.print(sb.toString()); } } }2.第二题看了一下,直接骗了13%
3.第三题亦是如此,也骗了13%
流下菜鸡的泪水,
全部评论
(2) 回帖