题目搜集于各位前辈,侵删。
第一题
import java.util.Scanner;
public class c1201 {
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();
System.out.println(Integer.toBinaryString(n));
}
sc.close();
}
}
第二题
import java.util.Scanner;
//貌似第二组数据是有问题的
public class c1202 {
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 K = sc.nextInt();
int[][] arr = new int[n][n];
int[][] temp = new int[n][n];
int[][] ans = new int[n][n];
for(int i = 0;i<n;i++) {
for(int j = 0;j<n;j++) {
arr[i][j] = sc.nextInt();
temp[i][j] = arr[i][j];
}
}
for(int k = 2;k<=K;k++) {
for(int i = 0;i<n;i++) {
for(int j = 0;j<n;j++) {
int sum = 0;
for(int p = 0;p<n;p++) {
sum+=arr[i][p]*arr[p][j];
}
ans[i][j] = sum;
}
}
for(int i = 0;i<n;i++) {
for(int j = 0;j<n;j++) {
temp[i][j] = ans[i][j];
}
}
}
for(int i = 0;i<n;i++) {
for(int j = 0;j<n;j++) {
if(j == 0) {
System.out.print(ans[i][j]);
}else {
System.out.print(" "+ans[i][j]);
}
}
System.out.println();
}
}
sc.close();
}
}
第三题
import java.util.Scanner;
public class c1201 {
static Node root ;
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 a = sc.nextInt();
Node node = search(root,a);
if(node == null) {
root = new Node(a);
System.out.print(-1);
}else {
System.out.print(node.value);
if(a<node.value) {
Node n = new Node(a);
node.left = n;
}else {
Node n = new Node(a);
node.right = n;
}
}
}
sc.close();
}
static class Node{
int value;
Node left = null;
Node right = null;
public Node(int value) {
super();
this.value = value;
}
}
static Node search(Node root,int a) {
if(root == null) {
return root;
}
if(a < root.value) {
if(root.left == null) {
return root;
}else {
return search(root.left,a);
}
}else {
if(root.right == null) {
return root;
}else {
return search(root.right,a);
}
}
}
}
第四题
import java.util.Scanner;
//45 00 00 34 7a 67 40 00 40 06 63 5a 0a cd 0a f4 7d 38 ca 09 cd f6 00 50 b4 d7 ae 1c
//45 00 00 c6 56 5a 40 00 34 06 e0 45 cb d0 2e 01 0a cd 0a f4 00 50 ce 61 e1 e9 b9 ee 47 c7 37 34
public class c1204 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = Integer.parseInt(sc.nextLine());
for(int t=1;t<=T;t++) {
String s = sc.nextLine();
String[] ss = s.split(" ");
int len = Integer.parseInt(ss[2]+ss[3], 16);
int[] source = new int[4];
int[] des = new int[4];
for(int i = 0;i<4;i++) {
source[i] = Integer.parseInt(ss[12+i],16);
des[i] = Integer.parseInt(ss[16+i],16);
}
int sourcePort = Integer.parseInt(ss[20]+ss[21], 16);
int desPort = Integer.parseInt(ss[22]+ss[23], 16);
System.out.println("Case #"+t);
System.out.println("Total length = "+len+" bytes");
System.out.println("Source = "+source[0]+"."+source[1]+"."+source[2]+"."+source[3]);
System.out.println("Destination = "+des[0]+"."+des[1]+"."+des[2]+"."+des[3]);
System.out.println("Source Port = "+sourcePort);
System.out.println("Destination Port = "+desPort);
}
sc.close();
}
}