当前位置 : 主页 > 编程语言 > java >

【笔试】浪潮集团2020秋招研发卷

来源:互联网 收集:自由互联 发布时间:2022-06-30
第1题 #includeiostream using namespace std ; int main () { int n , num = 1 , maxr = 1 ; cin n ; int * r = new int [ n ]; //创建长为n的数组 int * r1 = new int [ n ]; //备用数组 for ( int i = 0 ; i n ; i ++ ) { cin r [ i ]; //写入

第1题【笔试】浪潮集团2020秋招研发卷_子序列
【笔试】浪潮集团2020秋招研发卷_子序列_02

#include<iostream>
using namespace std;

int main()
{
int n, num = 1, maxr = 1;
cin >> n;
int *r = new int[n];//创建长为n的数组
int *r1 = new int[n];//备用数组
for (int i = 0; i < n; i++)
{
cin >> r[i];//写入数字
}
for (int i = 0; i < n; i++)
{
r1[i] = r[i];//从原数组中复制第i个数字,以防止原数组在计算过程中被改变
for (int j = i + 1; j < n; j++)
{
r1[j] = r[j];//从原数组中复制第j个数字
if (r1[i] + 1 == r1[j])//判断相邻两数字是否递增1
{
num = num + 1;//递增1子序列的长度
r1[i] = r1[j];
}
}
if (num > maxr)//更新递增1子序列的长度
{
maxr = num;
}
num = 1;
}
cout << n - maxr << endl;
system("PAUSE");
}

代码通过率为91%

第2题
【笔试】浪潮集团2020秋招研发卷_数组_03
【笔试】浪潮集团2020秋招研发卷_子序列_04
python版本

intput_1=raw_input('')

intput_2=map(int,raw_input('').split())

dict1={}
dict2={}
for i in range(1,101):

if i %2==1 :
dict1[i]=1
elif i %2 ==0 :
dict2[i]=1

for j in intput_2:
if j in dict1:
dict1[j]=0
if j in dict2:
dict2[j]=0

# print dict2
temp_num=0
temp_ben=2 #注意起始位位置初始值
max_num=1
max_ben=1

for m in dict2:
if dict2[m] == 1:
temp_num+=1
elif temp_num>max_num:
max_num=temp_num
max_ben=temp_ben

temp_ben=m+2
temp_num=0
else:
temp_ben = m + 2
if m==100 and temp_num>max_num and dict2[m] == 1:
max_num = temp_num
max_ben = temp_ben



temp_num2=0
temp_ben2=1 #注意起始位位置初始值
max_num2=1
max_ben2=1

for m in dict1:
if dict1[m] == 1:
temp_num2+=1
elif temp_num2>max_num2:
max_num2=temp_num2
max_ben2=temp_ben2

temp_ben2=m+2
temp_num2=0
else:
temp_ben2 = m + 2
if m==99 and temp_num2>max_num2 and dict1[m] == 1: #遍历到最后一项
max_num2 = temp_num2
max_ben2 = temp_ben2

if max_num>max_num2:
print str(max_ben)+" "+ str(max_num)
else:
print str(max_ben2) + " " + str(max_num2)

代码通过率为36%


上一篇:【Java】File类
下一篇:没有了
网友评论