3,882
社区成员




[ar:Michael Jackson]
[ti:Beat it]
[1090] Beat It 避开!
[3230] 谨以此歌告诫年轻的朋友避免不必要的麻烦
[8650] 暴力不能解决一切问题,只会伤害到自己
[12770] 制作人:河洲
[20610] 1st Verse They Told Him 他们告诉他:
[40160] Don't You Ever Come Around Here “你胆敢再来?
[42720] Don't Wanna See Your Face You Better Disappear 你最好消失!
[45840] The Fire's In Their Eyes 怒火在他们眼中升腾
[48340] And Their Words Are Really Clear 话语也说得格外明白
[ar:Michael Jackson]
[ti:Beat it]
[00:01.09]Beat It 避开!
[00:03.23]谨以此歌告诫年轻的朋友避免不必要的麻烦
[00:08.65]暴力不能解决一切问题,只会伤害到自己
[00:12.77]制作人:河洲
[00:20.61]1st Verse] They Told Him 他们告诉他:
[00:40.16]Don't You Ever Come Around Here “你胆敢再来?
[00:42.72]Don't Wanna See Your Face, 不想再见你,
[00:43.98]You Better Disappear 你最好消失!
[00:45.84]The Fire's In Their Eyes 怒火在他们眼中升腾
[00:48.34]And Their Words Are Really Clear 话语也说得格外明白
$ g++ test.cpp //这里编译
$ ./a.out txt new_txt//这里运行
$ cat new_txt //查看运行后的结果输出文件
[ar:Michael Jackson]
[ti:Beat it]
[00:01.09] Beat It 避开!
[00:03.23] 谨以此歌告诫年轻的朋友避免不必要的麻烦
[00:08.65] 暴力不能解决一切问题,只会伤害到自己
[00:12.77] 制作人:河洲
[00:20.61] 1st Verse They Told Him 他们告诉他:
[00:40.16] Don't You Ever Come Around Here “你胆敢再来?
[00:42.72] Don't Wanna See Your Face You Better Disappear 你最好消失!
[00:45.84] The Fire's In Their Eyes 怒火在他们眼中升腾
[00:48.34] And Their Words Are Really Clear 话语也说得格外明白
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
string format(int num)
{
num = num/10;
int i = num%100;
num = num/100;
int j = num%100;
num = num/100;
int k = num%100;
char buf[100];
sprintf(buf, "%02d:%02d.%02d", k, j, i);
return buf;
}
int main(int argc, char* argv[])
{
ifstream ifs(argv[1]);
ofstream ofs(argv[2]);
string line;
char buf[1024];
int num;
while (getline(ifs, line))
{
if (sscanf(line.c_str(), "[%d]%[^\n]", &num, buf) != 2)//这个地方改下
{
ofs << line << endl;
}
else
{
ofs << "[" << format(num) << "]" << buf << endl;
}
}
return 0;
}
~/test$ cat txt
[ar:Michael Jackson]
[ti:Beat it]
[1090] Beat It 避开!
[3230] 谨以此歌告诫年轻的朋友避免不必要的麻烦
[8650] 暴力不能解决一切问题,只会伤害到自己
[12770] 制作人:河洲
[20610] 1st Verse They Told Him 他们告诉他:
[40160] Don't You Ever Come Around Here “你胆敢再来?
[42720] Don't Wanna See Your Face You Better Disappear 你最好消失!
[45840] The Fire's In Their Eyes 怒火在他们眼中升腾
[48340] And Their Words Are Really Clear 话语也说得格外明白
~/test$ ./a.out txt new_txt
~/test$ cat new_txt
[ar:Michael Jackson]
[ti:Beat it]
[00:01.09]Beat
[00:03.23]谨以此歌告诫年轻的朋友避免不必要的麻烦
[00:08.65]暴力不能解决一切问题,只会伤害到自己
[00:12.77]制作人:河洲
[00:20.61]1st
[00:40.16]Don't
[00:42.72]Don't
[00:45.84]The
[00:48.34]And
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
string format(int num)
{
num = num/10;
int i = num%100;
num = num/100;
int j = num%100;
num = num/100;
int k = num%100;
char buf[100];
sprintf(buf, "%02d:%02d.%02d", k, j, i);
return buf;
}
int main(int argc, char* argv[])
{
ifstream ifs(argv[1]);
ofstream ofs(argv[2]);
string line;
char buf[1024];
int num;
while (getline(ifs, line))
{
if (sscanf(line.c_str(), "[%d]%s", &num, buf) != 2)
{
ofs << line << endl;
}
else
{
ofs << "[" << format(num) << "]" << buf << endl;
}
}
return 0;
}