Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <string.h>
- #pragma warning(disable: 4996)
- using namespace std;
- FILE* input, * output;
- //VAR 7
- //int main()
- //{
- //
- // ifstream input;
- // input.open("IN.txt");
- //
- // ofstream output;
- // output.open("OUT.txt");
- //
- // char s[256];
- //
- // while (!input.eof())
- // {
- // int counter = 0;
- // input.getline(s, 255);
- // int len = strlen(s);
- // if (len == 0)
- // {
- // /*input.get();
- // input.ignore();*/
- // output << endl;
- // continue;
- // }
- // int pos = 0;
- // for (unsigned long long i = 0; i < len - 1; i++)
- // {
- // if ((s[i] == ' ' and s[i + 1] != ' ') || (i == 0 and s[1] != ' '))
- // {
- // counter++;
- // pos=i;
- // }
- // }
- // if (counter > 1)
- // {
- // int newSize = len - (len - pos);
- // char * answ = new char[pos+1];
- // for (unsigned long long i = 0; i < pos; i++)
- // {
- // answ[i] = s[i];
- // }
- // answ[pos] = '\0';
- // if (!input.eof())
- // {
- // output << answ << endl;
- // }
- // else
- // {
- // output << answ;
- // }
- // delete[] answ;
- // }
- // else
- // {
- // output << endl;
- // }
- //
- // }
- // input.close();
- // output.close();
- //}
- ////VAR 8
- int main()
- {
- ifstream input;
- input.open("IN.txt");
- ofstream output;
- output.open("OUT.txt");
- char s[256];
- while (!input.eof())
- {
- int counter = 0;
- input.getline(s, 255);
- int len = strlen(s);
- if (len == 0)
- {
- continue;
- }
- int pos1 = 0;
- int pos2 = 0;
- for (unsigned long long i = 0; i < len - 1; i++)
- {
- if ((s[i] == ' ' and s[i + 1] != ' ') || (i == 0 and s[1] != ' '))
- {
- counter++;
- }
- if (counter == 2)
- {
- pos1 = i;
- for (int j = 1; j < len - 1-pos1; j++)
- {
- if ((s[i + j] != ' ' and s[i + j + 1] == ' ') || (i + j) >= len)
- {
- pos2 = i + j;
- break;
- }
- }
- break;
- }
- }
- if (counter > 1)
- {
- int j = 0;
- char* answ = new char[len-(pos2-pos1)+1];
- for (unsigned long long i = 0; i < len; i++,j++)
- {
- answ[j]= s[i];
- if (i == pos1-1)
- {
- i = pos2;
- }
- }
- answ[len - (pos2 - pos1)-1] = '\0';
- output << answ << endl;
- delete[] answ;
- }
- else
- {
- output << '*' << endl;
- }
- }
- input.close();
- output.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement