题目要求
穿越火线的军衔有:列兵,三等兵,二等兵,一等兵,下士…一直到元帅。
每一个军衔都必须要达到一定经验值才能够获得。现在假设有n个军衔,达到每个军衔所需要的经验值分别为a1,a2,a3…an而且a1<a2<a3<a4<…<an
CF里面每玩一局就会获得相应的经验值,假设某位玩家当前拥有经验值x,现在他玩了一局爆破任务,获得了y点经验。我们想知道他玩了这局爆破之后,军衔是什么。
Input
多组数据输入。
第一行为n,代表CF中有n种军衔(n<20)
第二行为n个数,代表每一个军衔所需要的经验值
第三行有两个数,分别是x和y
所有输入均为正整数,最大的那个数不超过10000
Output
输出该玩家最终的军衔。
Sample Input
Raw
3
10 20 30
5 3
3
10 20 30
5 10
3
10 20 30
30 5
3
10 20 30
5 5
Sample Output
Raw
0
1
3
1
水题目偷懒不多说了=v=
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(void)
{
int n;
int a[30];
while (scanf("%d",&n)!=EOF)
{
for (int i = 0; i < n; i++)
cin >> a[i];
int x, y,sum;
cin >> x;
cin >> y;
sum = x + y;
for (int i = 0; i < n; i++)
{
if (sum < a[i])
{
cout << i << endl;
break;
}
}
if (sum > a[n-1])
cout << n << endl;
}
return 0;
}