诚心求一份大佬的刚刚笔完网易的答案被 15:00那场
我的笔试题是回文串 素数个数 买票 最后一个是背包问题 只a出来一个 有思路但是不通过 想看看大佬咋写的 蟹蟹~!
本人分享一个买票的,自测没有问题,死活过不了,是一点都没有过的那种。
#include<iostream>
#include<vector>
using namespace std;
int main(){
int T;
cin>>T;
int time1 = 8;
int time2 = 0;
int time3 = 0;
string am = "am";
string bm = "bm";
string af ="";
vector<string>ss;
while (T)
{
int sum = 0;
string out="";
int n;
cin>>n;
int temp;
vector<int>res;
vector<int>vec;
for(int i = 0;i < n;i++){
cin>>temp;
res.push_back(temp);
}
for(int j = 0;j<n-1;j++){
cin>>temp;
vec.push_back(temp);
}
for(int i = 0;i < n;i++){
if(i == n-1){
sum += res[i];
break;
}
// int a = res[i] + res[i+1];
if(res[i] + res[i+1] > vec[i]){
sum += vec[i];
i += 2;
}else
{
sum += res[i];
i++;
}
}
int mid = 0;
mid = sum/60;
sum %= 60;
int hour = 0;
if(mid != 0){
int hour = mid/60;
mid%=60;
}
int top = 0;
hour += time1;
if(hour > 12){
af = bm;
hour-=12;
}
else
{
af = am;
}
if(hour < 12){
// cout<<0<<hour<<":";
string aa = to_string(0);
string bb = to_string(hour);
out = out+aa+bb+":";
}else
{
// cout<<hour<<":";
string bb = to_string(hour);
out = out+bb+":";
}
if(mid < 10){
// cout<<0<<mid<<":";
string aa = to_string(0);
string bb = to_string(mid);
out = out+aa+bb+":";
}else
{
// cout<<mid<<":";
string aa = to_string(mid);
out = out+aa+":";
}
if(sum <10){
// cout<<0<<sum<<" ";
string aa = to_string(0);
string bb = to_string(sum);
out = out + aa+bb+" ";
}else
{
// cout<<sum<<" ";
string aa = to_string(sum);
out = out + aa+" ";
}
// cout<<af<<endl;
out = out + af;
ss.push_back(out);
T--;
}
for(auto &elem:ss)
cout<<elem<<endl;
return 0;
}