#include <iostream>
#include <string>
#include <fstream>

using namespace::std;

int main(){
	string line;
//	string temp;
	int fa;
	int la;
	int l;
	int frel;
	int fnofollow;
	int counter=0;

	ifstream in("DATA3.txt", ios::in);
	ofstream out("OUT3.txt", ios::out);
	
	
	do {
//		for (int i=0; i<5; i++){
	getline(in,line);

	l=line.length();
//	cout << l << " ";
	fa=line.find("<a");
	cout << fa << " ";
	la=line.find("/a>");
//	cout << la;
	line=line.substr(fa, ((la - fa)+3));
	
	frel = line.find("rel=\"");
//	cout << line[frel+4];
	fnofollow = line.find("nofollow");
	if (frel != -1) {
		if (fnofollow == -1) {
			if ((line[frel+5]) != '\"'){
				for (int i=frel+5; i < line.length(); i++) {
					if (line[i] == '\"') {
						line.insert(i," nofollow");
						i = line.length();
					}
				}
			}
			else if ((line[frel+5]) == '\"') {
				line.insert(frel+5,"nofollow");	
			}
		}
	}
	else if (frel == -1) {
		for (int j=fa; j < line.length(); j++) {
			if ((line[j] == '>') && (line[j-2] != '/')) {
				line.insert(j, " rel=\"nofollow\"");
				j = line.length();
			}
			else if ((line[j] == '>') && (line[j-1] == 'a') && (line[j-2] == '<')) {
				line.insert(j, " rel=\"nofollow\"");
				j = line.length();
			}
		}
	}

	out<<line<<endl;
//	out<<line<<endl;


	counter++;
	//}
	} while(counter < 5);

	return(0);
}
