rendered paste body#include <cstdio>
#include <ctype.h>
#include <string>
#include <iostream>
using namespace std;
int main (void)
{
bool writeDown=true;
int i=0;
//For Query.in
int wordnumber=0;
int amountOfWords=1;
int Word=0;
//For text.in
int Sentencenumber=0;
int amountOfSentences=1;
int Sentence=0;
bool print0=true;
FILE *INPUT;
INPUT = fopen( "query.in", "r");
//checks how many lines
while (!feof(INPUT))
{
char temphold=fgetc(INPUT);
if (temphold == ' ')
{amountOfWords++;}
}
fclose(INPUT);
INPUT = fopen( "query.in", "r");
//Words which user searches for
string wordlist[amountOfWords];
int storeaddress[amountOfWords];
wordlist[0]=" ";
i=0;
wordnumber=0;
while (!feof(INPUT))
{
char temphold;
temphold= fgetc(INPUT);
if( temphold >= 97 && temphold <= 122)
{temphold = toupper(temphold);}
if( temphold == '\n')
{
break;
}
if( temphold == ' ')
{
wordlist[wordnumber]=wordlist[wordnumber]+" ";
wordnumber++;
}
i++;
wordlist[wordnumber]=wordlist[wordnumber]+temphold;
}
fclose(INPUT);
INPUT = fopen("text.in","r");
while (!feof(INPUT))
{
char temphold=fgetc(INPUT);
if (temphold == '.' )
{amountOfSentences++;}
}
string sentencelist[amountOfSentences];
sentencelist[0]=" ";
fclose(INPUT);
INPUT = fopen("text.in","r");
while (!feof(INPUT))
{
char temphold;
temphold= fgetc(INPUT);
if( temphold >= 97 && temphold <= 122)
{temphold = toupper(temphold);}
if (temphold == '.' )
{
sentencelist[Sentencenumber] = sentencelist[Sentencenumber]+" ";
Sentencenumber++;
}
else
{
sentencelist[Sentencenumber]=sentencelist[Sentencenumber]+temphold;
}
i++;
}
wordlist[amountOfWords-1]= wordlist[amountOfWords-1] + " " ;
//DONE WITH READING
/*
cout << sentencelist[0]<< "\n\n"; cout << sentencelist[1]<< "\n\n";
cout << sentencelist[2]<< "\n\n"; cout << sentencelist[3]<< "\n\n";
cout << sentencelist[4]<< "\n\n"; cout << sentencelist[5]<< "\n\n";
cout << sentencelist[6]<< "\n\n"; cout << sentencelist[7]<< "\n\n";
cout << wordlist[0]<< "\n\n";
cout << wordlist[1]<< "\n\n";
cout << wordlist[2]<< "\n\n";
cout << amountOfWords<< "\n\n";
*/
fclose(INPUT);
INPUT = fopen("query.out","w");
while(Sentence < amountOfSentences)
{
writeDown=true;
Word=-1;
i=0;
while(Word < amountOfWords-1)
{
i++;
Word++;
//cout << Word ;
//cout << sentencelist[Sentence].find(wordlist[Word]) << " ";
if( sentencelist[Sentence].find(wordlist[Word]) != string::npos )
{
int x=0;
storeaddress[i]=sentencelist[Sentence].find(wordlist[Word]);
while(x<i)
{
if(storeaddress[x]==storeaddress[i])
{
writeDown=false;
break;
}
x++;
}
//cout <<"T2 " ;
//cout << sentencelist[Sentence] << "\n"<< wordlist[Word] << "\n\n" ;
}
else if( sentencelist[Sentence].find(wordlist[Word]) == string::npos )
{
//cout << "T1 " ;
writeDown=false;
break;
}
}
Sentence++;
string output;
if(writeDown==true)
{
fprintf(INPUT,"%i ", Sentence);
print0=false;
}
}
if ( print0==true)
{
fprintf(INPUT,"0");
}
fprintf(INPUT,"\n");
return 0;
}