E类地址范围:240.0.0.0 - 255.255.255.255。其中240.0.0.0-255.255.255.254作为保留地址,主要用于Internet试验和开发
Finally语句在return前执行
‘1’对应ascll编码为49;"1"就当字符串处理,注意结果是111
21. (代码题)磁铁,A卷做过
思路:遍历每个字符,pCount记录Perfect连续次数,mCount记录Miss次数。字符为P,若pCount>4(初始值为1),score+=250,否则score+=200,最后pCount++;若为G,score+=100,pCount清零;若为M,mCount++,pCount清零,若 mCount>=3(初始值为0),证明失败,返回0。(感觉思路挺简单,但提交时最后一个测试用例过不了,还不知道为啥)
增:知道了,应该是越界了,score用long型应该可以通过
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
char[] chars = s.toCharArray();
int pCount=1,mCount=1;//分别记录P和M个数
int score = 0;
for (int i=0;i<chars.length;i++){
if (chars[i]=='P'){
pCount++;
if (pCount>4){
score += 250;
}else {
score += 200;
}
}else if (chars[i] == 'G'){
pCount = 1;
score += 100;
}else {
pCount = 1;
if (mCount==4){
score=0;
break;
}else {
mCount++;
}
}
}
System.out.println(score);
}
思路:例如输入数字112,设置list存储三位数中所有可以整除m的数。分别将其转化为字符数组,与n转化成的字符数组比较(都对其排序),若相等则count++。
(感觉思路可能有点问题,而且占内存很大,没有全部Ac)
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
char[] chars = String.valueOf(n).toCharArray();
int min = (int)Math.pow(10,chars.length-1);
int max = (int) Math.pow(10,chars.length);
int count = 0;
ArrayList<Integer> list = new ArrayList<>();
for (int i=min;i<max;i++){
if (i%m == 0){
list.add(i);
}
}
Arrays.sort(chars);
for(int i : list){
char[] temp = String.valueOf(i).toCharArray();
Arrays.sort(temp);
if (Arrays.equals(temp,chars))
count++;
}
System.out.println(count);
}