第一题
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String line = in.nextLine();
in.close();
String[] strings = line.split(",");
int tmp;
int m5 =0;
int m10=0;
for (int i = 0; i < strings.length; i++) {
tmp = Integer.parseInt(strings[i]);
if(tmp==5) {
m5++;
continue;
}
if(tmp==10) {
m10++;
m5--;
if(m5<0){
System.out.println("false,"+(i+1));
return;
}else {
continue;
}
}
if(tmp==20){
if(m10>0){
m10--;
m5--;
}else{
m5=m5-3;
}
if(m5<0){
System.out.println("false,"+(i+1));
return;
}else {
continue;
}
}
System.out.println("false,"+(i+1));
return;
}
System.out.println("true,"+strings.length);
}
}
第二题
import java.util.Scanner;
public class Main5 {
static int S,M,N;
static int[][] direction = {{0,1},{0,-1},{1,0},{-1,0}};
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
S = in.nextInt();
M = in.nextInt();
N = in.nextInt();
int[][] graph = new int[M][N];
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
graph[i][j] = in.nextInt();
}
}
in.close();
if(graph[M-1][N-1]==0){
System.out.println(0);
return;
}
dfs(graph,0,0);
if(graph[M-1][N-1]==0){
System.out.println(1);
}
}
static void dfs(int[][] graph, int i,int j){
if(i<0||i>=M||j<0||j>=N) {
return;
}
if(graph[i][j] == 0){
return;
}
graph[i][j] = 0;
for (int k=0;k<4;k++){
i += direction[k][0]*S;
j += direction[k][1]*S;
dfs(graph,i,j);
}
}
}
第三题
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String line = in.nextLine();
in.close();
String[] strings=line.split(",");
String str=strings[0];
int odd=Integer.valueOf(strings[1]);
StringBuilder[] builders = new StringBuilder[odd];
for (int j = 0; j < odd; j++) {
builders[j] = new StringBuilder();
}
int rowNumber = 0;
int index = 0;
int length = str.length();
while(index
for (int i = 0; i < odd; i++) {
if(rowNumber==i||(rowNumber+i+1)==odd) {
builders[i].append(str.charAt(index++));
if(index==length) break;
}
}
rowNumber=(rowNumber+1)%(odd-1);
}
for (int i = 0; i < odd ; i++) {
System.out.print(builders[i]);
}
}
}