继续刷牛客真题,列表补全。
分析:
这个题目同样简单,只需要考虑容器的大小是否还能装下东西,以及还需要装多少的问题。
问题:
1、Python输出需要是str,因此对得到的int型需要map映射为str才可以打印出来。
附上C++代码:
#include<iostream>
using namespace std;
int main()
{
int offset,n,l1,l2;
cin>>offset>>n>>l1>>l2;
if(l1>=offset)
{
cout<<offset<<" ";
cout<<(min(l1,n+offset))<<" ";
cout<<0<<" ";
cout<<(min(max(0,n+offset-l1),l2));
}
else
{
cout<<l1<<" ";
cout<<l1<<" ";
cout<<min(l2,offset-l1)<<" ";
cout<<(min(n+offset-l1,l2));
}
return 0;
}
附上Python代码:
a=list(map(int,input().split()))
res=[]
res.append(min(a[0],a[2]))
res.append(min(a[0]+a[1],a[2]))
res.append(min(a[3],max(a[0]-a[2],0)))
res.append(min(a[3],max(a[0]+a[1]-a[2],0)))
print(' '.join(map(str,res)))