5.10号快手笔试题思路
第一题:数字转换为中文表示法(AC)
思路:注意输入是0的情况,否则通过率87.5在等着你。。
import java.util.Scanner;
public class kuaishou {
public void convert(int number) {
if (number == 0) {// 注意边界条件
System.out.println("L");
return;
}
String[] num = { "L", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
String[] unit = { "", "S", "B", "Q", "W" };
String result = String.valueOf(number);
char[] ch = result.toCharArray();
StringBuilder str = new StringBuilder();// 使用StringBuilder来操作字符串频繁更新的情况
for (int i = 0; i < ch.length; i++) {
int c = (int) ch[i] - 48;// 从第一位依次判断
if (c != 0)
str.append(num[c] + unit[ch.length - i - 1]);
else {// 如果当前位是0的话
if (i == ch.length - 1) {
} // 如果是最后一位,则不需要操作
else {
if (ch[i + 1] != '0')// 否则,判断下一位是否为0,如果不为0,则追加“L”
str.append(num[0]);
}
}
}
System.out.println(str.toString());
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
if ("-1".equals(str))
return;
new kuaishou().convert(Integer.parseInt(str));
}
}
第二题:ACM-ICPC world final问题(AC)
思路:
博弈?找规律。。。看能不能被3整除,就这样ac了。。。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
for(int i = 0; i < m; i++){
int n = sc.nextInt();
if(n % 3 == 0)
System.out.println("don't be discouraged");
else
System.out.println("lucky");
}
}
} 第三题:有思路,但没写出来。。。求大神思路代码
#春招##笔试题目#
查看2道真题和解析