Advertisement
Guest User

Untitled

a guest
Nov 9th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <string.h>
  5. #pragma warning(disable: 4996)
  6. using namespace std;
  7. FILE* input, * output;
  8.  
  9. //VAR 7
  10.  
  11. //int main()
  12. //{
  13. // 
  14. //  ifstream input;
  15. //  input.open("IN.txt");
  16. //
  17. //  ofstream output;
  18. //  output.open("OUT.txt");
  19. //
  20. //  char s[256];
  21. // 
  22. //  while (!input.eof())
  23. //  {
  24. //      int counter = 0;
  25. //      input.getline(s, 255);
  26. //      int len = strlen(s);
  27. //      if (len == 0)  
  28. //      {
  29. //          /*input.get();
  30. //          input.ignore();*/
  31. //          output << endl;
  32. //          continue;
  33. //      }
  34. //      int pos = 0;
  35. //      for (unsigned long long i = 0; i < len - 1; i++)
  36. //      {
  37. //          if ((s[i] == ' ' and s[i + 1] != ' ') || (i == 0 and s[1] != ' '))
  38. //          {
  39. //              counter++;
  40. //              pos=i;
  41. //          }
  42. //      }
  43. //      if (counter > 1)
  44. //      {
  45. //          int newSize = len - (len - pos);
  46. //          char * answ = new char[pos+1];
  47. //          for (unsigned long long i = 0; i < pos; i++)
  48. //          {
  49. //              answ[i] = s[i];
  50. //          }
  51. //          answ[pos] = '\0';
  52. //          if (!input.eof())
  53. //          {
  54. //              output << answ << endl;
  55. //          }
  56. //          else
  57. //          {
  58. //              output << answ;
  59. //          }
  60. //          delete[] answ;
  61. //      }
  62. //      else
  63. //      {
  64. //          output << endl;
  65. //      }
  66. // 
  67. //  }
  68. //  input.close();
  69. //  output.close();
  70. //}
  71.  
  72. ////VAR 8
  73.  
  74. int main()
  75. {
  76.  
  77.     ifstream input;
  78.     input.open("IN.txt");
  79.  
  80.     ofstream output;
  81.     output.open("OUT.txt");
  82.  
  83.     char s[256];
  84.     while (!input.eof())
  85.     {
  86.         int counter = 0;
  87.         input.getline(s, 255);
  88.         int len = strlen(s);
  89.         if (len == 0)
  90.         {
  91.             continue;
  92.         }
  93.         int pos1 = 0;
  94.         int pos2 = 0;
  95.         for (unsigned long long i = 0; i < len - 1; i++)
  96.         {
  97.             if ((s[i] == ' ' and s[i + 1] != ' ') || (i == 0 and s[1] != ' '))
  98.             {
  99.                 counter++;
  100.             }
  101.             if (counter == 2)
  102.             {
  103.                 pos1 = i;
  104.                 for (int j = 1; j < len - 1-pos1; j++)
  105.                 {
  106.                     if ((s[i + j] != ' ' and s[i + j + 1] == ' ') || (i + j) >= len)
  107.                     {
  108.                         pos2 = i + j;
  109.                         break;
  110.                     }
  111.                 }
  112.                 break;
  113.             }
  114.  
  115.         }
  116.         if (counter > 1)
  117.         {
  118.             int j = 0;
  119.             char* answ = new char[len-(pos2-pos1)+1];
  120.             for (unsigned long long i = 0; i < len; i++,j++)
  121.             {
  122.                 answ[j]= s[i];
  123.                 if (i == pos1-1)
  124.                 {
  125.                     i = pos2;
  126.                 }
  127.                
  128.             }
  129.             answ[len - (pos2 - pos1)-1] = '\0';
  130.             output << answ << endl;
  131.             delete[] answ;
  132.         }
  133.         else
  134.         {
  135.             output << '*' << endl;
  136.         }
  137.     }
  138.     input.close();
  139.     output.close();
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement