FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
instratCode/a.cpp at master · aluka1994/instratCode · GitHub
aluka1994
/
instratCode
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
instratCode
/
a.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
88 lines (75 loc) · 1.63 KB
Breadcrumbs
instratCode
/
a.cpp
Copy path
File metadata and controls
88 lines (75 loc) · 1.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
dirent.h
>
#
include
<
sys/stat.h
>
#
include
<
string.h
>
#
include
<
stdio.h
>
#
include
<
iostream
>
#
include
<
vector
>
#
include
<
algorithm
>
#
include
<
fstream
>
#
include
<
sstream
>
#
include
<
iomanip
>
using
namespace
std
;
//
I am taking the directory name as default wc_input
//
if not we can scan that and send into the function
void
getFilesInDir
(vector<string> &files){
DIR
*dir;
struct
dirent
*entry;
struct
stat
info;
string dir_name =
"
wc_input
"
;
//
open
dir =
opendir
(dir_name.
c_str
());
if
(!dir){
cout <<
"
Please provide the directory...!!
"
<< endl;
return
;
}
//
read
while
( (entry=
readdir
(dir)) !=
NULL
){
if
(entry->
d_name
[
0
] !=
'
.
'
){
string path = dir_name +
'
/
'
+
string
(entry->
d_name
);
stat
(path.
c_str
(), &info);
if
(
S_ISREG
(info.
st_mode
))
files.
push_back
(
string
(path));
}
}
//
close
closedir
(dir);
sort
(files.
begin
(), files.
end
());
}
double
getMedian
(std::vector<
float
> &v,
int
s){
sort
(v.
begin
(), v.
end
());
if
(s%
2
){
return
v[s/
2
];
}
else
{
return
(v[s/
2
] + v[s/
2
-
1
])/
2
;
}
}
int
main
(){
vector<string> files;
getFilesInDir
(files);
int
size = files.
size
();
mkdir
(
"
wc_output
"
,
0777
);
ofstream out_file;
out_file.
open
(
"
./wc_output/med_result.txt
"
);
double
Median =
0.0
;
vector<
float
> input;
int
s =
0
;
for
(
int
i=
0
;i<size;i++){
ifstream
in_file
(files[i].
c_str
());
string num;
if
(!in_file.
is_open
()){
cout <<
"
Error: Not Entering The File
"
<< endl;
}
float
f;
while
(
getline
(in_file, num)){
istringstream
ss
(num);
ss >> f;
input.
push_back
(f);
s++;
Median =
getMedian
(input, s);
out_file <<
setprecision
(
1
) << fixed << Median << endl;
}
in_file.
close
();
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL