import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] group=new int[n];
for(int i=0;i<n;i ) {
group[i]=sc.nextInt();
}
int min=10000, startPoint=0, salary=100, base1=100, base2=100, temp=0;
for(int i=0;i<n;i ) {
if (group[i]<min) {
min=group[i];
startPoint=i;
}
}
temp=startPoint;
while(startPoint>1){
if(group[startPoint-1]<group[startPoint]&&group[startPoint-2]>group[startPoint-1]) {
base1=100;
}
if(group[startPoint-1]<group[startPoint]&&group[startPoint-2]<group[startPoint-1]) {
base1-=100;
}
if(group[startPoint-1]>group[startPoint]){
base1 =100;
}
salary =base1;
startPoint--; } while(startPoint==1) {
if(group[startPoint-1]>group[startPoint]) {
base1 =100;
}
else {
base1=100;
}
salary =base1;
startPoint--;
}
startPoint=temp;
while(startPoint<n-2) {
if(group[startPoint 1]<group[startPoint]&&group[startPoint 2]>group[startPoint 1]) {
base2=100;
}
if(group[startPoint 1]<group[startPoint]&&group[startPoint 2]<group[startPoint 1]) {
base2-=100;
}
if(group[startPoint 1]>group[startPoint]){
base2 =100;
}
salary =base2;
startPoint ;
}
while(startPoint==n-2) {
if(group[startPoint 1]>group[startPoint]) {
base2 =100;
}
else {
base2=100;
}
salary =base2;
startPoint ;
}
System.out.println(salary);
}
}
思路是先把所有人的工龄存到一个int数组,找到工龄最短的人的下标,然后往两边遍历。遇到工龄更大的人就此人工资加100,然后加进总
;如果工龄比当前的人更小,则看是否比另一端的人更小(如果在边界就只需要考虑一侧),如果是就把工资重归100;其他情况工资则减少一百。因为两边遍历要分开考虑,所以初始化了base1和base2两个int来更新每个人的工资值。应该还有优化的空间。抛砖引玉和大佬们交流下哈#字节跳动##笔试题目#