-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.cpp
58 lines (50 loc) · 1.19 KB
/
3.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
/*
3. Write a C/C++ program that reads text from a file, then delete the existing comment and save the output text file (without comment). Also count and print the number of deletion.
*/
#include <bits/stdc++.h>
using namespace std;
int del;
bool m_cmt=false;
string rem_cmt(string str){
int n=str.length();
string res="";
bool s_cmt=false;
for(int i=0;i<n;i++){
if(str[i]=='/' && str[i+1]=='/'){
s_cmt=true;
m_cmt=false;
del++;
break;
}
else if(str[i]=='/' && str[i+1]=='*'){
s_cmt=false;
m_cmt=true;
i++;
del++;
}
else if(str[i]=='*' && str[i+1]=='/'){
m_cmt=false;
s_cmt=false;
i++;
}else if(s_cmt==false && m_cmt==false){
res+=str[i];
}
}
return res;
}
int main()
{
fstream fin,fout;
fin.open("input.txt");
fout.open("output.txt");
string str;
while(getline(fin,str)){
// cout<<str<<endl;
string ss= rem_cmt(str);
fout<<ss<<endl;
}
cout<<"Number of deletion : "<<del<<endl;
fin.close();
fout.close();
return 0;
}