社区讨论
全RE求助
P7374 [COCI2018-2019#5] Titlovi参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo1lv9x8
- 此快照首次捕获于
- 2023/10/22 23:10 2 年前
- 此快照最后确认于
- 2023/11/02 23:54 2 年前
调了半天了,总是运行错误。
本人觉得可能是输入的问题(不确定),但改了还错。
有没有大佬帮忙看看?
CPP#include<bits/stdc++.h>
#include<string>
using namespace std;
long long n,t,ch;
string sta;
struct node{
long long number;// 编号
string time;//起始时间 和 结束时间
string book;//字幕内容
};
node a[110];
void zh(long long f[10]){ //调整时间
f[1]+=t; //毫秒调整
if(t>=0){ //加的(向后调整)
//超过进率,多的往前进,余数留下
if(f[1]>=1000) f[2]+=f[1]/1000,f[1]%=1000;
if(f[2]>=60) f[3]+=f[2]/1000,f[2]%=1000;
if(f[3]>=60) f[4]+=f[3]/1000,f[3]%=1000;
}else{ //减的(向前调整)
long long sum=0;
//如果变负向前借
if(f[1]<0){
sum=abs(f[1])/1000; //求要借的
//如果补上sum还不够,再+1
//当前位的值变为 进制-余数
if(abs(f[1])%1000!=0) sum++,f[1]=1000-abs(f[1])%1000;
else f[1]=0;
//否则(刚好补上)归零
f[2]-=sum;
//借来的减去
}
//同上
if(f[2]<0){
sum=abs(f[2])/1000;
if(abs(f[2])%1000!=0) sum++,f[2]=1000-abs(f[2])%1000;
else f[2]=0;
f[3]-=sum;
}
//同上
if(f[3]<0){
sum=abs(f[3])/1000;
if(abs(f[3])%1000!=0) sum++,f[3]=1000-abs(f[3])%1000;
else f[3]=0;
f[4]-=sum;
}
}
}
void pd(string sta,int k){
string st=sta+' ';
long long sum=0,x=4,y=4;
long long f1[10]={0},f2[10]={0};
//这个循环把 起始时间 和 结束时间 的 时、分、秒、毫秒分离出来
for(int i=0;i<st.size();i++){
if(i==13) i=17;
if(st[i]==':'||st[i]==','||st[i]==' '){
//这里一开始我弄混了,最后只好倒序存
if(x>0) f1[x]=sum,x--;
else f2[y]=sum,y--;
sum=0;
}else sum=sum*10+(st[i]-48);
}
//调整时间
zh(f1);
zh(f2);
//输出,位数不够补 0
cout<<a[k].number<<endl;
if(f1[4]<10) cout<<"0"<<f1[4]<<":";
else cout<<f1[4]<<":";
if(f1[3]<10) cout<<"0"<<f1[3]<<":";
else cout<<f1[3]<<":";
if(f1[2]<10) cout<<"0"<<f1[2]<<",";
else cout<<f1[2]<<",";
if(f1[1]<10) cout<<"00"<<f1[1]<<" --> ";
else if(f1[1]<100) cout<<"0"<<f1[1]<<" --> ";
else cout<<f1[1]<<" --> ";
if(f2[4]<10) cout<<"0"<<f2[4]<<":";
else cout<<f2[4]<<":";
if(f2[3]<10) cout<<"0"<<f2[3]<<":";
else cout<<f2[3]<<":";
if(f2[2]<10) cout<<"0"<<f2[2]<<",";
else cout<<f2[2]<<",";
if(f2[1]<10) cout<<"00"<<f2[1]<<endl;
else if(f2[1]<100) cout<<"0"<<f2[1]<<endl;
else cout<<f2[1]<<endl;
cout<<a[k].book<<endl;
if(k==n) cout<<"#";
else cout<<endl;
}
int main(){
while(1){//读入
cin>>ch;//读入编号
n++;
a[n].number=ch;
getchar();
getline(cin,a[n].time);//读入字幕开始播放时间 和 字幕结束播放时间
while(1){ //读入字幕内容
getline(cin,sta);
//如果为空说明这条字幕内容已读完
//如果是 # 说明所有字幕已读完
if(!(sta.empty()==0&&sta!="#")) break;
//book 不为空,得加一个'\n'
if(a[n].book.empty()==0) a[n].book=a[n].book+'\n'+sta;
//否则直接加上
else a[n].book=a[n].book+sta;
}
//是 # break
if(sta=="#") break;
}
cin>>t;
// 对每条字幕时间调整
for(int i=1;i<=n;i++) pd(a[i].time,i);
return 0;
}
```cpp
回复
共 4 条回复,欢迎继续交流。
正在加载回复...