一.编程题
public class Main
{
public static int getNum(int num)
{
//累加汽水的个数
int sum = 0;
//while(num > 0) 死循环
while(num > 1)
{
//兑换的汽水的个数 /3
sum += num / 3;
//剩余的空瓶子 /3 + %3
num = num / 3 + num % 3;
if(num == 2)
{
//借一瓶
++sum;
break;
}
}
return sum;
}
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int num;
while((num = s.nextInt()) != 0)
{
System.out.println(getNum(num));
}
}
}
查找两个字符串a,b中的最长公共子串_牛客题霸_牛客网 (nowcoder.com)
好难!摆烂了,专注力不够,题解都40多分钟,下次再看吧hhh
public class Main
{
//假设str1长度短
public static String getMaxSubstr(String str1, String str2)
{
char[] arr1 = str1.toCharArray();
char[] arr2 = str2.toCharArray();
int len1 = arr1.length;
int len2 = arr2.length;
//最长子串的起始位置
int start = 0;
//最长子串的长度
int maxLen = 0;
//多增加一行一列,作为辅助状态
//状态: 以a的第i个字符结尾和以b的第j个字符结尾的最长公共子串的长度
int[][] maxSubLen = new int[len1 + 1][len2 + 1];
for(int i = 1; i <= len1; ++i)
{
for(int j = 1; j <= len2; ++j)
{
//如果第i个字符和第j个字符相等,则进行累加
if(arr1[i - 1] == arr2[j - 1])
{
maxSubLen[i][j] = maxSubLen[i - 1][j - 1] + 1;
//更新
if(maxLen < maxSubLen[i][j])
{
maxLen = maxSubLen[i][j];
start = i - maxLen;
}
}
}
}
return str1.substring(start, start + maxLen);
}
public static void main(String[] args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String str1;
String str2;
while((str1 = reader.readLine()) != null)
{
str2 = reader.readLine();
if(str1.length() < str2.length())
System.out.println(getMaxSubstr(str1, str2));
else
System.out.println(getMaxSubstr(str2, str1));
}
}
}
二.选择题错题
别说了,数据结构忘光光了!以后复习
question one :
存储顺序 and 逻辑顺序
存储空间(物理顺序)
question two:
question three:
后序遍历:左右根
中序遍历:左根右
根据后序遍历知道根是:a ,结合中序遍历,知道左节点是:b
右边是fegcd,再根据后序遍历 可知根是d
答案:c
question four:
question five:
question six: