笔试能够在本地IDE写,而后复制上去java
N:闹钟数 <= 100
HI 小时 Mi 分钟 0 - 24
X 去教室走几分钟 0 - 60
A 上课时间web
输入案例:
3 定三个闹钟
5 0 闹钟1
6 0 闹钟2
7 0 闹钟3
59 去教室走几分钟
6 59 几点上课app
输出:
6 0svg
我代码过了 80%,比较菜!!编码
import java.util.Scanner; import java.util.Stack; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); int lasttime = 0; //记录闹钟,时间最长的在最外面 Stack<Integer> lasttimes = new Stack<Integer>(); for (int i = 0; i < n; i++) { String[] str = sc.nextLine().split(" "); //这里将时间统一为分钟 lasttime+=60*Integer.parseInt(str[0]); lasttime+=Integer.parseInt(str[1]); lasttimes.push(lasttime); lasttime=0; } //获取去学校时长 lasttime = sc.nextInt(); sc.nextLine(); //获取上课时间 String[] str = sc.nextLine().split(" "); int inclass = 60*Integer.parseInt(str[0])+Integer.parseInt(str[1]); //上课时间减掉来学校时间 lasttime = inclass - lasttime; //取出闹钟比较时间长度 while(!lasttimes.isEmpty()) { int clock = lasttimes.pop(); //若是闹钟时间小于最后时间,输出结束 if(lasttime>=clock) { int h = (int) Math.floor(clock/60); int m = clock%60; System.out.println(h+" "+m); return; } } } }
给一个二进制字符串如: 1001010
而后在给一个 K 值 : 4
根据k值进行 ^ 异或运算 K次 ,每运算一次就向左变移动一位
就是这样:
1001010000 ^
–100101000 ^
----10010100 ^
-----1001010
而后编码结果:
1110100110spa
输入案例:
4 K
1110100110 编码后的字符串code
输出:
1001010xml
这个当时没作出来token
package ks; public class Main { /* * * 1001010000 * 0100101000 * 0010010100 * 0001001010 * * 1110100110 * * */ public static void main(String[] args) { deCode("1110100110",4); } public static void deCode(String code,int k) { long num = Long.valueOf(code, 2); //一、长度 int length = code.length() - k+1; //二、末尾是否为0 boolean isZero = (num%2==0); //三、最高位为0是第几个 StringBuffer sb =new StringBuffer(); for(int i =0 ;i<length;i++) { if(isZero&&i==length-1) { sb.append(0); }else { sb.append(1); } } //最大的数算出来而后进行判断 long key = Long.valueOf(sb.toString(), 2); while(key>(1<<k)) { if(num==code(key)) { System.out.println(Long.toBinaryString(key)); return; } key-=2; } } private static long code(long key) { for (int i = 0; i < 3; i++) { key = (key<<1)^key; } return key; } }
要求:没人至少发100,工龄长的人要比旁边的多100字符串
输入
4 员工数
3 9 2 7 入职了几年
输出:
600 就是这个亚子: [ 100 , 200 , 100 , 200 ]
不知道为啥,一直 40% 过不去。。。。
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = Long.parseLong(sc.nextLine()); long[] year = new long[(int) n]; String[] line = sc.nextLine().split(" "); for (int i = 0; i < year.length; i++) { year[i] = Long.parseLong(line[i]); } System.out.println(count(year)); } public static long count(long[] year) { //一、先左一遍 long[] money = new long[year.length]; long pre = 0; money[0] = 100; for (int i = 1; i < year.length; i++) { if(money[i]==0) money[i] = 100; pre = year[i-1]; if(pre==year[i]) { continue; } //谁年限大,谁加100 if(pre>year[i]) { money[i-1]=money[i]+100; }else { money[i]=money[i-1]+100; } } //在右一遍 for (int i = year.length-2; i > 0; i--) { pre = year[i+1]; if(pre==year[i]) { continue; } if(pre>year[i]) { money[i+1]=money[i]+100; }else { money[i]=money[i+1]+100; } } pre = 0; for (long i : money) { pre+=i; } return pre; } }