-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.cpp
130 lines (120 loc) · 2.38 KB
/
input.cpp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "input.h"
void input :: sort_rollno()
{
// Reading roll nos from file
infile.open("expand-rollno.out");
//cout<<"expand-rollno.out";
infile >> t_branches;
for(i=0; i<t_branches; i++)
{
infile >> roll_size[i];
for(int j=0; j<roll_size[i]; j++)
{
infile >> roll_no[i][j];
cout<<roll_no[i][j];
}
cout<<"\n";
}
infile.close();
//outfile.open("input_sorted.out");
// Sorting of roll nos.
for(i=0;i<t_branches;i++)
{
for(j=0; j<roll_size[i]; j++)
{
rno[j] = roll_no[i][j];
}
sort(rno, rno+roll_size[i]); // Sort function
for(j=0; j<roll_size[i]; j++)
{
roll_no[i][j] = rno[j];
}
}
// Writing into file(input_sorted.out)
outfile.open("sort-rollno.out");
outfile << t_branches <<endl;
for(int i=0; i<t_branches; i++)
{
outfile << roll_size[i] <<endl;
for(int j=0; j<roll_size[i]; j++)
{
outfile << roll_no[i][j] << " ";
}
outfile <<endl;
}
outfile.close();
}
void input :: rm_duplicate_rollno()
{
// Reading roll nos from file
infile.open("sort-rollno.out");
infile >> t_branches;
for(i=0; i<t_branches; i++)
{
infile >> roll_size[i];
for(int j=0; j<roll_size[i]; j++)
{
infile >> roll_no[i][j];
}
}
infile.close();
for(i=0;i<t_branches;i++)
{
for(j=0; j<roll_size[i]; j++)
{
rno[j] = roll_no[i][j];
}
for(j=0; j<roll_size[i]; j++)
{ // Removing duplicate values
if(rno[j]==rno[j+1])// || rno[j+1]==rno[j+2])
{
for(k=j; k<=roll_size[i]; k++)
{
rno[k] = rno[k+1]; //shifts each element one position above
}
roll_size[i]--;
j=0;
}
}
// Removing roll nos that are not for exam
for(j=0; j<roll_size[i]; j++)
{
if(rno[j]<0)
{
int a,b;
a = rno[j];
b = -1 * a;
for(k=0; k<roll_size[i]; k++)
{
if(rno[k] == a || rno[k] == b)
{
//rno[j+1]=0;
for (int l=k; l<=roll_size[i]; l++)
{
rno[l] = rno[l+1]; //shifts each element one position above
}
roll_size[i]--;
}
}
j--;
}
}
for(j=0; j<roll_size[i]; j++)
{
roll_no[i][j] = rno[j];
}
}
// Writing into file
outfile.open("non-redundant-rollno.out");
outfile << t_branches <<endl;
for(int i=0; i<t_branches; i++)
{
outfile << roll_size[i] <<endl;
for(int j=0; j<roll_size[i]; j++)
{
outfile << roll_no[i][j] << " ";
}
outfile <<endl;
}
outfile.close();
}