搜题目网上都有原题
1、N个数之和
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int count=0;
for(int i=0;i<n;i++){
count+=in.nextInt();
}
System.out.println(count);
}
}
2、
点击消除
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Stack<Character> s=new Stack<>();
String str=scan.nextLine();
int length=str.length();
for(int i=0;i<length;i++){
if(s.isEmpty()){
// 栈空直接插入
s.push(str.charAt(i));
}else{
if(s.peek()!=str.charAt(i)){
// 压栈元素不等于栈顶元素,压栈
s.push(str.charAt(i));
}else{
s.pop();
}
}
}
if(s.isEmpty()){
System.out.print(0);
}else{
for(char c:s){
System.out.print(c);
}
}
}
}
3、
ranko的手表
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String t1 = sc.nextLine();
String t2 = sc.nextLine();
List<Integer> list1 = new ArrayList<>();
List<Integer> list2 = new ArrayList<>();
for(int i=0;i<60*24;i++){
int hour = i/60;
int minu = i%60;
if((t1.charAt(0)=='?'||t1.charAt(0)-'0'==hour/10)&&(t1.charAt(1)=='?'||t1.charAt(1)-'0'==hour%10)
&&(t1.charAt(3)=='?'||t1.charAt(3)-'0'==minu/10)&&(t1.charAt(4)=='?'||t1.charAt(4)-'0'==minu%10))
list1.add(i);
if((t2.charAt(0)=='?'||t2.charAt(0)-'0'==hour/10)&&(t2.charAt(1)=='?'||t2.charAt(1)-'0'==hour%10)
&&(t2.charAt(3)=='?'||t2.charAt(3)-'0'==minu/10)&&(t2.charAt(4)=='?'||t2.charAt(4)-'0'==minu%10))
list2.add(i);
}
int max = 0;
int min = 60*24;
for(int i=0;i<list1.size();i++)
for(int j=0;j<list2.size();j++){
if(list1.get(i)<list2.get(j)){
max = Math.max(list2.get(j)-list1.get(i),max);
min = Math.min(list2.get(j)-list1.get(i),min);
}
}
System.out.print(min+" "+max);
}
}
#亚信安全##面经笔经##测试开发##23届秋招笔面经##一起秋招吧#