题目搜集于各位前辈,侵删。
第一题
输入:
3
3
5
8
输出:
1
2
4
import java.util.Scanner;
public class i1701 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t=0;t<T;t++) {
int n = sc.nextInt();
int count = 0;
for(int i = 2;i<n;i++) {
if(isPrime(i)) {
count++;
}
}
System.out.println(count);
}
sc.close();
}
static boolean isPrime(int n) {
for(int i = 2;i<n;i++) {
if(n%2==0) {
return false;
}
}
return true;
}
}
第二题
输入:
1
1 2 3 4 5
6 5 8 9 7
6 5 7 8 4
5 6 3 2 1
2 3 1 4 5
1 2 3 4 5
3 2 1 4 5
6 5 4 1 2
6 2 1 4 5
3 2 1 3 4
7 8 9 6 3
1 2 4 5 6
3 2 1 4 5
3 2 1 8 6
3 0 0 1 0
输出:
886 734 804 1112 832
2074 1700 1852 2634 2005
1791 1462 1589 2280 1740
942 722 770 1234 954
848 662 710 1072 788
import java.util.Scanner;
public class i1702 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t=0;t<T;t++) {
int[][] arr1 = new int[5][5];
int[][] arr2 = new int[5][5];
int[][] arr3 = new int[5][5];
int[][] ans12 = new int[5][5];
int[][] ans123 = new int[5][5];
for(int i = 0;i<5;i++) {
for(int j = 0;j<5;j++) {
arr1[i][j] = sc.nextInt();
}
}
for(int i = 0;i<5;i++) {
for(int j = 0;j<5;j++) {
arr2[i][j] = sc.nextInt();
}
}
for(int i = 0;i<5;i++) {
for(int j = 0;j<5;j++) {
arr3[i][j] = sc.nextInt();
}
}
for(int i = 0;i<5;i++) {
for(int j = 0;j<5;j++) {
int temp = 0;
for(int k = 0;k<5;k++) {
temp+=arr1[i][k]*arr2[k][j];
}
ans12[i][j] = temp;
}
}
for(int i = 0;i<5;i++) {
for(int j = 0;j<5;j++) {
int temp = 0;
for(int k = 0;k<5;k++) {
temp+=ans12[i][k]*arr3[k][j];
}
ans123[i][j] = temp;
}
}
for(int i = 0;i<5;i++) {
for(int j = 0;j<5;j++) {
if(j==0) {
System.out.print(ans123[i][j]);
}
System.out.print(" "+ans123[i][j]);
}
System.out.println();
}
}
sc.close();
}
}
第三题
输入:
5
AAAA
ABC
ZZ
A
AAA
0
输出:
AAAA
A
AAA
import java.util.Scanner;
public class i1703 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String[] ss = new String[n];
for(int i = 0;i<n;i++) {
ss[i] = sc.next();
}
int x = sc.nextInt();
for(int i = 0;i<n;i++) {
int hash = 0;
for(int j = 0;j<ss[i].length();j++) {
hash += ss[i].charAt(j)-'A';
}
if(hash == x) {
System.out.println(ss[i]);
}
}
sc.close();
}
}
第四题
import java.util.Scanner;
import java.util.Stack;
//太麻烦了,不做了,先打个样,下次一定
public class i1704 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t=0;t<T;t++) {
String s = sc.next();
//首先需要一个栈来存后一半
Stack<String> stack = new Stack<String>();
//然后要一个字符串来一个一个字符读
String temp = new String();
for(int i = 0;i<s.length();i++) {
if(s.charAt(i)=='(') {
//开始处理之前存的,并缩进
}else if(s.charAt(i)==')') {
//开始处理之前存的,不缩进
}else if(s.charAt(i)=='>') {
//入栈,缩进
}else if(s.charAt(i)=='.') {
//class加
}else if(s.charAt(i)=='#') {
//id加
}else if(s.charAt(i)=='*') {
}else {
temp+=String.valueOf(s.charAt(i));
}
}
}
sc.close();
}
}