1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <string>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <iostream>
using namespace std;
const string CDFV = "Input.txt"; //...........input file
const string CSKYR = " .,!?:;()"; //............ Seperators
void EditLine(string dfv,int &nr);
bool SearchSymbols(string row, char ch, char ch1, char ch2);
int main()
{
int nr = 0;
EditLine(CDFV,nr);
}
void EditLine(string CDFV, int &nr)
{
string row;
string word;
std::string s;
std::stringstream out;
ifstream fd(CDFV.c_str());
int zpr = 0, spr = 0;
while (!fd.eof()){
getline(fd,row);
while ((zpr = row.find_first_not_of(CSKYR, spr)) != -1) // zpr - position of next word's first symbol
{
nr++; // word's number
spr = row.find_first_of(CSKYR, zpr); // find seperator position in row
word = row.substr(zpr, spr - zpr); // get a word
if (SearchSymbols(word, 'o','y','a') == true ) {
out << nr;
s = out.str();
row.replace(zpr,spr-zpr,s);
}
}
zpr = 0, spr = 0;
cout<<row<<endl;
}
fd.close();
}
bool SearchSymbols(string row, char ch, char ch1, char ch2)
{
bool Symbols = false;
for (unsigned int i = 0; i < row.length(); i++)
if (tolower(row[i]) == tolower(ch)|| tolower(row[i]) == tolower(ch1) || tolower(row[i]) == tolower(ch2))
Symbols = true;
return Symbols;
}
|