本文主要是介绍笔试强训day02,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
牛牛的快递
import math
a,b = input().split()
a = float(a)
price = 20
if a>1:price += math.ceil(a)-1
if b=='y':price += 5
print(price)
最小花费爬楼梯
#include <bits/stdc++.h>
const int N = 1e5+10;
int cost[N];
int n;
int dp[N];int main()
{std::cin>>n; for(int i = 0;i<n;++i)std::cin>>cost[i];for(int i = 2;i<=n;++i){dp[i] = std::min(dp[i-1]+cost[i-1],dp[i-2]+cost[i-2]);}std::cout<<dp[n]<<std::endl;return 0;
}
数组中两个字符串的最小距离
from math import *
t = int(input())
s1,s2 = input().split()
idx1,idx2 = -1,-1
ans = inf
for _ in range(t):s = input()if s1 == s:idx1 = _elif s2 == s:idx2 = _if idx1 !=-1 and idx2 != -1:ans = min(ans,abs(idx1-idx2))
print(-1 if ans == inf else ans)
这篇关于笔试强训day02的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!