-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_ID_binary.cpp
More file actions
107 lines (105 loc) · 1.76 KB
/
convert_ID_binary.cpp
File metadata and controls
107 lines (105 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<fstream>
#include<ctype.h>
using namespace std;
int main()
{
int id;
char title[1000], ID[100];
ifstream in;
ofstream out;
in.open("docId.txt", ios::in);
out.open("Index/ID_Title_Index", ios::out | ios::binary);
string line;
while(1)
{
getline(in, line);
// cout<<line<<endl;
if(line.length() == 0)
break;
for(int k=0; line[k]!='\0'; k++)
{
if(isdigit(line[k]))
{
int count = 0;
while(isdigit(line[k]))
{
ID[count++] = line[k++];
}
ID[count] = '\0';
id = atoi(ID);
}
else if(line[k] == '`')
{
k++;
int count = 0;
while(line[k]!='`')
{
title[count++] = line[k++];
}
title[count] = '\0';
break;
}
else
k++;
}
// cout<<id<<" "<<title<<endl;
out.write((char*)&id, 4);
int length = strlen(title);
out.write((char*)&length, 4);
out.write(title, strlen(title));
}
in.close();
in.open("docId2.txt", ios::in);
while(1)
{
getline(in, line);
// cout<<line<<endl;
if(line.length() == 0)
break;
for(int k=0; line[k]!='\0'; k++)
{
if(isdigit(line[k]))
{
int count = 0;
while(isdigit(line[k]))
{
ID[count++] = line[k++];
}
ID[count] = '\0';
id = atoi(ID);
}
else if(line[k] == '`')
{
k++;
int count = 0;
while(line[k]!='`')
{
title[count++] = line[k++];
}
title[count] = '\0';
break;
}
else
k++;
}
// cout<<id<<" "<<title<<endl;
out.write((char*)&id, 4);
int length = strlen(title);
out.write((char*)&length, 4);
out.write(title, strlen(title));
}
in.close();
out.close();
return 0;
}