Subscribe Us

Responsive Advertisement

Advertisement

problem 3.cpp

#include<bits/stdc++.h>

#include<fstream>

#include<iostream>

using namespace std;

int main()

{


  int numOfDelete=0;

  ifstream inn;

  inn.open("input.txt");

  string ans="";

  int multiLineComment=0;

  string in;

  while(getline(inn,in))

  {


             int singleLineComment=0;

           for(int i=0;i<in.size()-1;i++)

           {

               if(in[i]=='/'&&in[i+1]=='/'&&multiLineComment==0)

               {

                    numOfDelete++;

                   singleLineComment=1;

                   break;


               }

               if(in[i]=='/'&&in[i+1]=='*'&&multiLineComment==0)

               {

                    numOfDelete++;

                   multiLineComment=1;

                   i++;

                   continue;



               }

               if(multiLineComment==0)

               ans+=in[i];

               if(in[i]=='*'&&in[i+1]=='/')

               {

                    multiLineComment=0;

                    i++;


               }



           }

           if(multiLineComment==0&&singleLineComment==0)

           {


               ans+=in[in.size()-1];

               ans+='\n';

           }




  }


    inn.close();

    ofstream out;

    out.open("output.txt");

    out<<ans<<endl;

    out.close();



   cout<<"Number of deletion is : "<<numOfDelete<<endl;


}


Post a Comment

0 Comments