CCF第一题作答整理
跳一跳
L = [int(x) for x in input().split(' ')]
fore = 0
sum = 0
for i in L:
if(i==0):
break
if(i==1):
sum+=1
fore = 0
if(i==2):
fore+=2
sum+=fore
print(sum)
最小差值
int main()
{
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a,a+n);
int ans = 1e5;
for (int i = 0; i < n-1; i++)
{
ans = min(ans,a[i+1]-a[i]);
}
cout << ans << endl;
return 0;
}
打酱油
int main()
{
int n;
cin >> n;
int count = 0;
while(n>=50)
{
count += 7;
n -= 50;
}
while(n>=30)
{
count += 4;
n -= 30;
}
while(n>0)
{
count += 1;
n -= 10;
}
cout << count << endl;
return 0;
}
中间数
int main()
{
int n;
cin>>n;
int *p=new int[n];
int i,j;
for(i=0;i<n;i++)
{
cin>>p[i];
}
int middleNumber=-1;
for(i=0;i<n;i++)
{
int greater=0;
int less=0;
for(j=0;j<n;j++)
{
if(p[j]>p[i])
greater++;
if(p[j]<p[i])
less++;
}
if(greater==less)
middleNumber=p[i];
}
cout<<middleNumber;
return 0;
}