# java实现：牛客网中偏简单的那些代码题：找了那些通过率百分之30以上的题来练习，慢慢提高自己的代码能力

java实现：牛客网中偏简单的那些代码题：找了那些通过率百分之30以上的题来练习，慢慢提高自己的代码能力

### 题目1：

package test21080825;

import java.util.Scanner;

public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = 0;
int j = 0;
int arr[] = new int[1000 * 1000 + 1];
while (sc.hasNext()) {

arr[j] = sc.nextInt();
j++;
if (arr[0] * 2 < j) {
break;
}
}
n = 2 * arr[0] + 1;
int m = arr[0];
for (int k = 0; k < n; k++) {
// System.out.println(arr[k]);
}
int min = arr[1] + arr[1 + m];
for (int i = 1; i < m + 1; i++) {

//System.out.println(min);
if (min > arr[i] + arr[i + m]) {
min = arr[i] + arr[i + m];
// System.out.println("min" + min);
}
}
System.out.println(min - 2);

}

}


### 题目二：

package test21080825;

import java.util.Scanner;

public class Main3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.nextLine();
char[] arr = str.toCharArray();
String[] arr2 = new String[arr.length];
boolean bool = true;
for (int i = 0; i < arr.length; i++) {

if (!(arr[i] >= 'A' && arr[i] <= 'Z')) {
// System.out.println("Dislikes");
bool = false;
break;

}
if (i + 1 < arr.length) {
if ((arr[i] == arr[i + 1])) {
// System.out.println("Dislikes");
bool = false;
break;
}
}
for (int j = i + 1; j < arr.length - 1; j++) {
if (arr[i] == arr[j]) {
for (int a = i+1; a < j; a++) {
for (int b = j+1; b < arr.length; b++) {
if (arr[a] == arr[b]) {
// System.out.println("Dislikes");
bool = false;
break;
}
}
}
}
}
// System.out.println("Likes");

}
if (bool == false) {
System.out.println("Dislikes");
} else {
System.out.println("Likes");
}

}
}
}


### 题目三：



public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int m = sc.nextInt();
int n = sc.nextInt();
int a = m / 4;// 横坐标除4取整
int b = m % 4;// 横坐标取余
int c = n / 4;// 纵坐标除4取整
int d = n % 4;// 纵坐标取余
int sum12 = 0;//前边两行放的蛋糕数量一样
int sum34 = 0;//3，4行蛋糕数量也一样
int sum = 0;最后的总的蛋糕数量
int sum1234 = 0;前边四行的蛋糕数量
// 先得出前四行分别的数目，首先前面两行一样，后边两行一样
// 首先是1，2两行放的蛋糕都一样
if (d == 1) {
sum12 = c * 2 + 1;
} else if (d == 0) {
sum12 = (c - 1) * 2 + 2;
} else {
sum12 = c * 2 + 2;
}
// 然后是3，4两行，放的蛋糕都一样
sum34 = n - sum12;
// 前面四行一共放蛋糕数量如下
sum1234 = 2 * (sum12 + sum34);

// 前边计算了前面四行分别的数目，接下来是往纵看，
if (b == 1) {
sum = a * sum1234 + sum12;
}else
if (b == 2) {
sum = a * sum1234 + 2 * sum12;
}else
if (b == 3) {
sum = a * sum1234 + sum12 * 2 + sum34;
}
else {
sum = a * sum1234;
}
System.out.println(sum);

}
}
}

### 题目四：

package test20180826;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while (sc.hasNext()) {
int a = sc.nextInt();
int b = sc.nextInt();
if(a>=0&&a<=1024&&b>=0&&b<=1024){
if(a==b){
System.out.println(1);
}else{
System.out.println(0);
}
}else{
System.out.println(-1);
}
}
}
}



### 题目五：

package test20180826;

import java.util.Scanner;

public class Main2 {
/*
* 感觉我这个思路蛮简单，首先是看可以对8整除不，
*
* 如果不能在看可以选出几个8和6组合，
*
* 8的个数从app/8到0个变化，取相应的6的个数。
*
* 如果上边取不到整数，就相当于不可行。
*
* 我前后使用了一个标记，boo,如果取到整数了
*
* 就是true，否则是false,
*/

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean boo = false;
while (sc.hasNext()) {
int app = sc.nextInt();
if (app % 8 == 0) {
System.out.println(app / 8);
boo = true;
} else {
for (int i = app / 8; i >= 0; i--) {
if ((app - i * 8) % 6 == 0) {
System.out.println(i + (app - i * 8) / 6);
boo = true;
break;
}
}
if (boo == false) {
System.out.println(-1);
}
}
}
}
}


### 题目七：

package main20180827;

import java.util.Scanner;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str1 = sc.nextLine();
String str2 = sc.nextLine();
int i = 0;
int j = 0;
while (i < str1.length() && j < str2.length()) {
if (str1.charAt(i) == str2.charAt(j)) {
i++;
j++;
} else {
i++;
}

}
if (j == str2.length()) {
System.out.println("Yes");
} else {
System.out.println("No");
}

}
}
}


### 题目八：

package main20180827;

import java.util.Scanner;

public class Main3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int k=0;
String str = sc.nextLine();
String[] arr = str.split(" ");
int i;
for( i=0;i<arr.length;i++){
k=0;
for(int j=0;j<arr.length;j++){
if(arr[i].equals(arr[j])){
k++;
//					System.out.println(k+"  ");
//					System.out.println("下标"+i);
}
}
if(k>=arr.length/2){
//System.out.println(arr.length/2);
System.out.println(arr[i]);
break;
}
}

}
}
}