Advertisement
Guest User

Untitled

a guest
Apr 1st, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. int main(void)
  4. {
  5.     using namespace std;
  6.     string sor;
  7.     int i;
  8.     bool noprint = false;
  9.     int noprintfrom;
  10.     while (getline(cin,sor)){
  11.         noprintfrom = 0;
  12.         for (i = 0; i < sor.length(); ++i){        
  13.             if (sor[i] == '/' && sor[i+1] == '/'){
  14.                 sor.erase(i,sor.length()-i);
  15.             }
  16.             if (sor[i] == '/' && sor[i+1] == '*'){
  17.                 noprintfrom = i;
  18.                 noprint = true;
  19.             }
  20.             if (sor[i] == '*' && sor[i+1] == '/'){
  21.                 noprint = false;
  22.                 sor.erase(noprintfrom,noprintfrom - i);
  23.             }
  24.         }
  25.         if (noprint){
  26.             sor.erase(noprintfrom,sor.length()-noprintfrom);        
  27.         }
  28.         cout << sor << endl;
  29.     }
  30.     /*//Előző próbálkozás
  31.     char stream;
  32.     char prevstream;
  33.     bool cp_on = false;
  34.     int commentstyle;
  35.     while(cin >> stream){
  36.         //komment kezdete
  37.         if (stream == '/'){
  38.             prevstream = stream;
  39.             cin >> stream;
  40.             if (stream == '/' || stream == '*'){
  41.                 cp_on = true;
  42.                 if ( stream = '/')
  43.                     commentstyle = 1;
  44.                 else
  45.                     commentstyle = 2;
  46.             }else
  47.                 cout << prevstream << stream;
  48.         }
  49.         //komment vége
  50.         if (cp_on){
  51.             if (commentstyle == 1){
  52.                 if (stream == '\n' || stream == '\r')
  53.                     cp_on = false;
  54.             }else{
  55.                 if ( stream == '*'){
  56.                     prevstream = stream;
  57.                     cin >> stream;
  58.                     if ( stream == '/' )
  59.                         cp_on = false;
  60.                     else
  61.                         cout << prevstream;
  62.                 }
  63.             }
  64.  
  65.         }
  66.         if (!cp_on)
  67.                 cout << stream;
  68.     }*/
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement