1
byte[] src,dst;
dst=new String (src,”GBK”).getbytes(“UTF-8”)
//实现了GBK编码字节流到UTF-8编码字节流的转换:
2
A:寻找下一个空的位置,存放
B:再次使用一个不同的哈希算法计算一次
C:使用链表存 (HashMap)
第一题:
思路 : 通过规律发现如果 [i][j]位置放了蛋糕,则[i+2][j]和[i][j+2] 不能放蛋糕。
import java.util.Scanner;
public class Main3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
int h = sc.nextInt();
int[][] a = new int[w][h];
int count = 0;
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
if (a[i][j]==0){
count++;
if ( i+2 <w){
a[i+2][j]=1;
}
if (j+2 <h){
a[i][j+2]=1;
}
}
}
}
System.out.println(count);
}
}
第二题:
public class Solution {
public static int strToInt(String str){
char[] chars = str.toCharArray();
if (str.isEmpty()) return 0;
int sign = 1;
if (chars[0]=='-'){
sign = - 1;
chars[0] = '0';
}else if (chars[0]=='+'){
chars[0] = '0';
}
int ret = 0;
for (int i = 0; i <str.length() ; i++) {
if (chars[i]<'0' || chars[i]>'9'){
ret = 0;
break;
}
ret = ret*10 + chars[i]-'0';
}
return ret*sign;
}
}