题解 | 【模板】序列操作
【模板】序列操作
https://www.nowcoder.com/practice/12da4185c0bb45918cfdc3072e544069
public class Program {
public static void Main() {
string line = System.Console.ReadLine();
int q = int.Parse(line);
System.Collections.Generic.List<int> list = new
System.Collections.Generic.List<int>();
for (int i = 0; i < q; i++) {
string[] parts = System.Console.ReadLine().Split();
int op = int.Parse(parts[0]);
if (op == 1) {
int x = int.Parse(parts[1]);
list.Add(x);
} else if (op == 2) {
list.RemoveAt(list.Count - 1);
} else if (op == 3) {
int idx = int.Parse(parts[1]);
System.Console.WriteLine(list[idx]);
} else if (op == 4) {
int idx = int.Parse(parts[1]);
int x = int.Parse(parts[2]);
list.Insert(idx + 1, x);
} else if (op == 5) {
list.Sort();
} else if (op == 6) {
list.Sort((a, b) => b.CompareTo(a));
} else if (op == 7) {
System.Console.WriteLine(list.Count);
} else if (op == 8) {
System.Console.WriteLine(string.Join(" ", list));
}
}
}
}

查看12道真题和解析