5
Feb 2, 2020
Mar 7, 2020
Oct 10, 101
Nov 21, 1211
Dec 29, 1229
Y 20200202
N 20200307
Y 01011010
Y 12111121
N 12291229
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @date 2021-9-8 - 21:28
* Created by Salmon
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bufferedReader.readLine());
for (int i = 0; i < n; i++) {
StringBuilder sb1 = new StringBuilder();
String[] s = bufferedReader.readLine().split("\\s+");
sb1.append(switchs(s[0]));
if(s[1].length() <= 2){
sb1.append(0);
sb1.append(s[1].charAt(0));
}else {
sb1.append(s[1].substring(0,2));
}
StringBuilder sb2 = new StringBuilder();
if(s[2].length() < 4){
for (int j = 0; j < 4 - s[2].length(); j++){
sb2.append(0);
}
}
sb2.append(s[2]);
String temp = sb1.toString();
if(sb1.reverse().toString().equals(sb2.toString())){
System.out.println("Y " + sb2 + temp);
}else {
System.out.println("N " + sb2 + temp);
}
}
}
public static String switchs(String s){
if(s.equals("Jan")){
return "01";
}else if(s.equals("Feb")){
return "02";
}else if(s.equals("Mar")){
return "03";
}else if(s.equals("Apr")){
return "04";
}else if(s.equals("May")){
return "05";
}else if(s.equals("Jun")){
return "06";
}else if(s.equals("Jul")){
return "07";
}else if(s.equals("Aug")){
return "08";
}else if(s.equals("Sep")){
return "09";
}else if(s.equals("Oct")){
return "10";
}else if(s.equals("Nov")){
return "11";
}else if(s.equals("Dec")){
return "12";
}
return "-1";
}
}
11 25
21 15 25 28 35 27 20 24 18 32 23
[3, 5]
[9, 9]
11 40
21 15 25 28 35 27 20 24 18 32 23
35
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @date 2021-9-8 - 21:28
* Created by Salmon
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String[] strings = bufferedReader.readLine().split("\\s+");
int n = Integer.parseInt(strings[0]);
int sign = Integer.parseInt(strings[1]);
String[] s = bufferedReader.readLine().split("\\s+");
bufferedReader.close();
int minIndex = 0,maxIndex = 0,max = 0;
int flag = 0;
int flag1 = 0;
for (int i = 0; i < n; i++) {
int temp = Integer.parseInt(s[i]);
max = Math.max(temp, max);
if(temp > sign){
if(flag == 0){
minIndex = i;
maxIndex = i;
flag++;
}
maxIndex = Math.max(maxIndex, i);
}else {
if(flag == 1){ //扫描到不合格数据时,至少找到一个区间
flag = 0;
flag1++;
System.out.println("[" + minIndex + "," + " " + maxIndex + "]");
}
}
}
if(flag1 == 0){
System.out.println(max);
}
}
}
2g50ttaq 0st9hk381
11feik2ir
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @date 2021-9-8 - 21:28
* Created by Salmon
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String[] s = bufferedReader.readLine().split("\\s+");
int n1 = s[0].length();
int n2 = s[1].length();
int n = Math.max(n1,n2);
bufferedReader.close();
StringBuilder balance = new StringBuilder();
for (int i = 0; i < Math.abs(n1 - n2); i++) {
balance.append(0);
}
if(n1 == n2){
;
}else if(n1 > n2) {
s[1] = balance.append(s[1]).toString();
}else if(n1 < n2){
s[0] = balance.append(s[0]).toString();
}
String[] strings = new String[30];
for (int i = 0; i < 30; i++) {
if(i < 10){
strings[i] = String.valueOf(i);
}else {
strings[i] = String.valueOf(Character.valueOf((char) ('a' + i - 10)));
}
}
StringBuilder res = new StringBuilder();
int carry = 0;
for (int i = n - 1; i >= 0; i--) {
int temp1 = Character.isAlphabetic(s[0].charAt(i)) ? s[0].charAt(i) - 'a' + 10 : s[0].charAt(i) - '0';
int temp2 = Character.isAlphabetic(s[1].charAt(i)) ? s[1].charAt(i) - 'a' + 10 : s[1].charAt(i) - '0';
int temp3 = temp1 + temp2 + carry;
if(temp3 >= 30){
carry = temp3 / 30;
res.append(strings[temp3 % 30]);
}else {
carry = 0;
res.append(strings[temp3]);
}
}
res.reverse();
for (int i = 0; i < res.length(); ) {
if(res.charAt(i) == '0'){
res.deleteCharAt(i);
}else {
break;
}
}
if(res.toString().equals("")){
System.out.println(0);
}else {
System.out.println(res);
}
}
}
20190523
20190523 Yes
0190523 Yes
190523 Yes`在这里插入代码片`
90523 Yes
0523 Yes
523 Yes
23 Yes
3 Yes
All Prime!
20191231
20191231 Yes
0191231 Yes
191231 Yes
91231 No
1231 Yes
231 No
31 Yes
1 No
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @date 2021-9-8 - 21:28
* Created by Salmon
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String s = bufferedReader.readLine();
bufferedReader.close();
int n = s.length();
int flag = 0;
for (int i = 0; i < n; i++) {
if(isPrime(Integer.parseInt(s))){
System.out.println(s + " " + "Yes");
flag++;
}else {
System.out.println(s + " " + "No");
}
s = s.substring(1);
}
if(flag == n){
System.out.println("All Prime!");
}
}
public static boolean isPrime(int num){
if(num == 1 || num == 0){
return false;
}
for (int i = 2; i <= Math.sqrt(num); i++) {
if(num % i == 0){
return false;
}
}
return true;
}
}
101 42
4 5
59 34 67 9 7
17 9 8 50 7
25 92 43 26 37
76 51 1 41 40
Round #4: 1 is out.
Round #5: 3 is out.
Winner(s): 2 4
42 101
4 5
59 34 67 9 7
17 9 18 50 49
25 92 58 1 39
102 32 2 6 41
Round #1: 4 is out.
Round #3: 2 is out.
Round #4: 1 is out.
Round #5: 3 is out.
No winner.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.*;
/**
* @date 2021-9-8 - 21:28
* Created by Salmon
*/
public class Main_2020_spring_5 {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String[] s = bufferedReader.readLine().split("\\s+");
int n1 = Integer.parseInt(s[0]);
int n2 = Integer.parseInt(s[1]);
String[] s1 = bufferedReader.readLine().split("\\s+");
int peopleNum = Integer.parseInt(s1[0]);
int round = Integer.parseInt(s1[1]);
hashMap2.put(n1, 1);
hashMap2.put(n2, 1);
hashMap1.put(Math.abs(n1 - n2),1);
StreamTokenizer streamTokenizer = new StreamTokenizer(bufferedReader);
int[][] nums = new int[peopleNum][round];
for (int i = 0; i < peopleNum; i++) {
for (int j = 0; j < round; j++) {
streamTokenizer.nextToken();
nums[i][j] = (int) streamTokenizer.nval;
}
}
bufferedReader.close();
boolean[] people = new boolean[peopleNum];
for (int i = 0; i < round; i++) {
for (int j = 0; j < peopleNum; j++) {
if(people[j] == true){ //淘汰的人直接跳过
continue;
}
if(hashMap2.containsKey(nums[j][i]) || !hashMap1.containsKey(nums[j][i])){
System.out.println("Round #" + (i + 1) + ": " + (j + 1) + " is out.");
people[j] = true; //淘汰此人;
}else {
createNums(nums[j][i]);
}
}
}
StringBuilder res = new StringBuilder();
for (int i = 0; i < peopleNum; i++) {
if(people[i] == false){
res.append(" ");
res.append(i + 1);
}
}
if(!(res.length() == 0)){
System.out.println("Winner(s):" + res);
}else {
System.out.println("No winner.");
}
}
static HashMap<Integer,Integer> hashMap1 = new HashMap<>(); // 差值
static HashMap<Integer,Integer> hashMap2 = new HashMap<>(); // 已经有过的值
public static void createNums(int num){
// List<Integer> list = new ArrayList<>();
// for (int temp1 : hashMap2.keySet()){
// list.add(temp1);
// }
// for (int key : list) {
// int temp = Math.abs(key - num);
// if(!hashMap1.containsKey(temp)){
// hashMap1.put(temp,1);
// }
// }
Integer[] integers = hashMap2.keySet().toArray(new Integer[0]);
for (int key : integers) {
int temp = Math.abs(key - num);
if(!hashMap1.containsKey(temp)){
hashMap1.put(temp,1);
}
}
if(!hashMap2.containsKey(num)){
hashMap2.put(num, 1);
}
}
}
这里遇到个问题:我一开始使用set将hashmap.keyset提取出来,然后发现如果我改变hashmap,keyset也会跟着改变,并抛出Exception in thread "main" java.util.ConcurrentModificationException
,所以只好多便利一遍将其变为数组;