爱奇艺

This commit is contained in:
xiongraorao 2018-09-15 21:26:27 +08:00
parent 1c2b8c5ebb
commit bc6d7c52d6
6 changed files with 233 additions and 1 deletions

View File

@ -13,7 +13,7 @@ public class Test {
private int a; private int a;
public static void main(String[] args) { public static void main(String[] args) {
System.out.println();
} }

View File

@ -0,0 +1,11 @@
package com.raorao.interview.iqiyi;
/**
* .
*
* @author Xiong Raorao
* @since 2018-09-15-9:53
*/
public class M {
}

View File

@ -0,0 +1,30 @@
package com.raorao.interview.iqiyi.t1;
import java.util.Scanner;
/**
* .
*
* @author Xiong Raorao
* @since 2018-09-15-10:42
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String s1 = input.substring(0, 3);
String s2 = input.substring(3, 6);
int front = s1.charAt(0) + s1.charAt(1) + s1.charAt(2) - '0' * 3;
int end = s2.charAt(0) + s2.charAt(1) + s2.charAt(2) - '0' * 3;
if (Math.abs(front - end) == 0) {
System.out.println(0);
} else if (Math.abs(front - end) <= 9) {
System.out.println(1);
} else if (Math.abs(front - end) <= 18) {
System.out.println(2);
} else {
System.out.println(3);
}
}
}

View File

@ -0,0 +1,72 @@
package com.raorao.interview.iqiyi.t2;
import java.util.ArrayList;
import java.util.Scanner;
/**
* .
*
* @author Xiong Raorao
* @since 2018-09-15-11:00
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int M = scanner.nextInt();
int P = scanner.nextInt();
ArrayList<Food> foods = new ArrayList<>();
for (int i = 0; i < N; i++) {
foods.add(new Food(i, scanner.nextInt()));
}
scanner.next();
for (int i = 0; i < M; i++) {
String[] temp = scanner.nextLine().split(" ");
int food = Integer.parseInt(temp[1]);
if (temp[0].equals("A")) {
Food f = new Food(foods.get(food - 1).id, foods.get(food - 1).num + 1);
foods.set(food - 1, f);
} else {
Food f = new Food(foods.get(food - 1).id, foods.get(food - 1).num - 1);
foods.set(food - 1, f);
}
}
foods.sort((e1, e2) -> e2.num - e1.num);
int ret = 1;
boolean flag = false;
int last = foods.get(0).num;
for (int i = 0; i < foods.size(); i++) {
if (foods.get(i).id == P - 1) {
System.out.println(ret);
return;
}
if(i > 0 && foods.get(i).num == last){
}else {
ret ++;
}
// if (i > 0 && foods.get(i - 1).num == foods.get(i).num) {
// flag = true;
// } else {
// if (!flag) {
// ret++;
// } else {
// ret = i + 1;
// flag = false;
// }
// }
}
}
static class Food {
int id;
int num;
public Food(int id, int num) {
this.id = id;
this.num = num;
}
}
}

View File

@ -0,0 +1,50 @@
package com.raorao.java.oop;
/**
* 块代码测试.
*
* @author Xiong Raorao
* @since 2018-09-09-22:24
*/
public class BlockTest {
public static void main(String[] args) {
new B();
System.out.println(A.a);
}
}
class A {
//public static final String a = new String("JD"); // this will call static block
public static final String a = "JD"; // this won't call static block
static {
System.out.println("A static block");
}
{
System.out.println("A block");
}
public A() {
System.out.println("A constructor");
}
}
class B extends A {
static {
System.out.println("B static block");
}
{
System.out.println("B block");
}
public B() {
System.out.println("B constructor");
}
}

View File

@ -0,0 +1,69 @@
package com.raorao.sword;
/**
* .
*
* @author Xiong Raorao
* @since 2018-09-12-23:54
*/
public class MatrixPath {
private static final int[][] directions = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
private int m;
private int n;
public static void main(String[] args) {
char[] input = "ABCESFCSADEE".toCharArray();
int rows = 3;
int cols = 4;
char[] str = "ABCCED".toCharArray();
boolean res = new MatrixPath().hasPath(input, rows, cols, str);
System.out.println(res);
}
public boolean hasPath(char[] matrix, int rows, int cols, char[] str) {
if (matrix == null || matrix.length == 0 || str == null || str.length == 0) {
return false;
}
m = rows;
n = cols;
char[][] grid = new char[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
grid[i][j] = matrix[i*n + j];
}
}
boolean[][] visited = new boolean[m][n];
for (int r = 0; r < m; r++) {
for (int c = 0; c < n; c++) {
if (backtracking(grid, r, c, visited, 0, str)) {
return true;
}
}
}
return false;
}
public boolean backtracking(char[][] grid, int r, int c, boolean[][] visited, int curLen,
char[] str) {
if(curLen == str.length){
return true;
}
if (r < 0 || r >= m || c < 0 || c >= n || grid[r][c] != str[curLen] || visited[r][c]) {
return false;
}
visited[r][c] = true;
for (int[] d : directions) {
if (backtracking(grid, r + d[0], c + d[1], visited, curLen + 1, str)) {
return true;
}
}
visited[r][c] = false;
return false;
}
}