#题目描述
局长有N种食物,每种食物有Ai份。
每天局长会吃一份食物,或者买一份食物(即每天只能进行吃或者买其中的一种动作),这样过了M天,现在局长想知道M天后第P种食物的份数排名(从大到小,相同并列,例如3 3 2,则排名为1 1 3)
N,M,P <= 100,Ai <= 1000
输入描述
第一行N M P
第二行N个数Ai
接下来M行,每行Ai或者Bi分别表示买一份食物i,吃一份食物i
输出描述
一个答案
样例输入
3 4 2
5 3 1
B 1
A 2
A 2
A 3
样例输出
1
题目分析
局长有且只有
N种食物,同时他每天也只吃或者买着N种食物中的一种(吃或者买只能发生一次,牛逼的局长,坚持而且有毅力
),故吃掉的话,则那种食物总数减一,买的话,那种食物总数加一,区别方式则是A和B来进行区分。然后最后循环和数组中第P种食物比较,比它多,则加一,比完后输出结果即可。
#代码实现
import java.util.Scanner;
public class tryA {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int M = scan.nextInt();
int P = scan.nextInt();
int food[] = new int[1000];
//每种食物的个数,循环读入数组中
for (int i = 0; i < N; i++) {
food[i] = scan.nextInt();
}
int k = 0;
while (k < M) {
char input1 = scan.next().charAt(0);
int input2 = scan.nextInt();
switch (input1){
//数组下标请注意-1,从零开始的
case 'B':food[input2-1]--;
break;
case 'A':food[input2-1]++;
break;
}
k++;
}
int aar_index = 1;
for (int i = 0; i < N; i++) {
if (food[i] > food[P-1]) {
aar_index ++;
}
}
System.out.println(aar_index);
}
}