fork download
  1. #include <cstdio>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. vector<char>input;
  9. char c = getchar();
  10.  
  11. while (c != EOF) {
  12. input.push_back(c);
  13. c = getchar();
  14. }
  15. /*kom /* *///* kom */jjjjss
  16. int inputLength = input.size();
  17. bool blockComment = false;
  18. bool lineComment = false;
  19. bool str = false;
  20.  
  21. for (int i = 0; i < inputLength; ++i) {
  22. if (!lineComment && !blockComment) {
  23. if (input[i] == '\"') {
  24. if (input[i - 1] == '\\') {
  25. putchar('\"');
  26. continue;
  27. } else {
  28. str = !str;
  29. putchar('\"');
  30. continue;
  31. }
  32. }
  33. }
  34.  
  35. if (!str) {
  36. if (lineComment && input[i] != '\n') {
  37. continue;
  38. } else if (lineComment && input[i] == '\n') {
  39. if (input[i - 1] == '\\') {
  40. continue;
  41. } else {
  42. lineComment = false;
  43. putchar('\n');
  44. continue;
  45. }
  46. }
  47.  
  48. if (blockComment && input[i] != '*') {
  49. continue;
  50. } else if (blockComment && input[i] == '*' && input[i + 1] == '/') {
  51. blockComment = false;
  52. i++;
  53. continue;
  54. } else if (blockComment && input[i] == '*' && input[i + 1] != '/') {
  55. continue;
  56. }
  57. }
  58.  
  59. if (input[i] != '/') {
  60. putchar(input[i]);
  61. } else {
  62. if(!str) {
  63. if (input[i + 1] == '*') {
  64. blockComment = true;
  65. i++;
  66. } else if (input[i + 1] == '/') {
  67. lineComment = true;
  68. i++;
  69. } else {
  70. putchar(input[i]);
  71. }
  72. } else {
  73. putchar(input[i]);
  74. }
  75. }
  76. }
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0s 5308KB
stdin
//kom
    /*kom /*  *///* kom  */jjjjss
/*komneb  // */dalej kom
nie kom //kom2
/*kom 3
kom4 */
nie kom2
printf("");
printf("//   ");
printf(" /* */ ");
printf("\n");
printf(" // \n /* \n */ ");
cout<<" Bla // Bla Bla\n";
cout<<" Bla /* Bla // */ // Bla"<<endl;
/ ala/ //alka
/* / ala/ // */
/ala*/
/ala*/* ala *./  */
// komentarz
// komentarz2 \
dalszy komentarzyk
perl/*/*/*///*//*//*//**//*//*//*//
/*/* /* ///*//*//*//**//*//*//*//*/
komentarz // czy nie komentarz
*//.*/.**./
/*hjfdsjhf
sdfjh
dsgfj
8?
/
8
**
//
*/
stdout
    
dalej kom
nie kom 

nie kom2
printf("");
printf("//   ");
printf(" /* */ ");
printf("\n");
printf(" // \n /* \n */ ");
cout<<" Bla // Bla Bla\n";
cout<<" Bla /* Bla // */ // Bla"<<endl;
/ ala/ 

/ala*/
/ala*


perl*

komentarz 
*