Skip to content

Commit da54579

Browse files
committed
操作序列
1 parent 89d9a0c commit da54579

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

Interview/bishi/wangyi.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,4 +1760,41 @@ public class Main {
17601760
System.out.println(res);
17611761
}
17621762
}
1763+
```
1764+
1765+
## 操作序列
1766+
1767+
[https://www.nowcoder.com/practice/b53bda356a494154b6411d80380295f5?tpId=122&&tqId=33683&rp=1&ru=/ta/exam-wangyi&qru=/ta/exam-wangyi/question-ranking](https://www.nowcoder.com/practice/b53bda356a494154b6411d80380295f5?tpId=122&&tqId=33683&rp=1&ru=/ta/exam-wangyi&qru=/ta/exam-wangyi/question-ranking)
1768+
1769+
```java
1770+
import java.util.Scanner;
1771+
1772+
public class Main {
1773+
public static void main(String[] args) {
1774+
Scanner sc = new Scanner(System.in);
1775+
int n = sc.nextInt();
1776+
int[] a = new int[n];
1777+
for (int i = 0; i < n; i++) {
1778+
a[i] = sc.nextInt();
1779+
}
1780+
if (n == 1)
1781+
System.out.println(a[0]);
1782+
if (n % 2 == 0) {
1783+
for (int i = n - 1; i >= 0; i -=2)
1784+
System.out.print(a[i] + " ");
1785+
for (int i = 0; i < n - 2; i += 2)
1786+
System.out.print(a[i] + " ");
1787+
System.out.print(a[n - 2]);
1788+
}
1789+
else {
1790+
for (int i = n - 1; i >= 0; i -= 2) {
1791+
System.out.print(a[i] + " ");
1792+
}
1793+
for (int i = 1; i < n - 2; i += 2)
1794+
System.out.print(a[i] + " ");
1795+
System.out.print(a[n-2]);
1796+
}
1797+
}
1798+
}
1799+
17631800
```

Interview/src/Main.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
import java.util.ArrayList;
2+
import java.util.Collections;
13
import java.util.Scanner;
24

35
public class Main {
46
public static void main(String[] args) {
57
Scanner sc = new Scanner(System.in);
6-
String s = sc.nextLine();
7-
int len = 1;
8-
int res = 1;
9-
for (int i = 1; i < s.length(); i++) {
10-
if (s.charAt(i) != s.charAt(i - 1)) {
11-
len++;
12-
res = Math.max(len, res);
13-
} else {
14-
len = 1;
15-
}
8+
int n = sc.nextInt();
9+
int[] a = new int[n];
10+
for (int i = 0; i < n; i++) {
11+
a[i] = sc.nextInt();
1612
}
17-
System.out.println(res);
13+
ArrayList<Integer> list = new ArrayList<>();
14+
for (int i = 0; i < n; i++) {
15+
list.add(a[i]);
16+
Collections.reverse(list);
17+
}
18+
StringBuilder sb = new StringBuilder();
19+
list.forEach(o -> sb.append(o + " "));
20+
System.out.println(sb.substring(0, sb.length() - 1));
21+
1822
}
1923
}

0 commit comments

Comments
 (0)