#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <cstdlib>


using namespace std;

    char cstr[9999], cstr2[9999], cstr3[9999];
    
void resetCstr(){
    for (int i = 0; i < 9999; ++i){
        cstr[i] = '\0';
        cstr2[i] = '\0';
        cstr3[i] = '\0';
    }
}




int main()
{
    ofstream fout   ("Out3.txt");
    ifstream fin    ("Data3.txt");
    
    string linkCode;
    string line;  
    int index1, index2;

    
    
    for (int i = 0; i < 5; ++i){
        /*
        resetCstr();
        
        linkCode = "";
        fin.getline(cstr, 9999, '\n');
        cout <<"i is:"<<i << ":" << cstr << "\n";
        sscanf(cstr, "%9999c<a%9999c/a>",&cstr3, &cstr2);
        cout << "cstr2 is:"<<cstr2;
        cout<<"\ncstr3 is:"<<cstr3;
        linkCode = cstr2;*/
//        cout << linkCode;
        fin.getline(cstr, 9999, '\n');
        line = cstr;
        index1 = (int)line.find("<a");
        index2 = (int)line.find("</a>");    
//        cout <<index1 << " " <<index2;
        
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!                
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!
        //MAKE SURE TO ADD ON </a>!!!!!!!!!!!!!!!!!!                                                                        
        
        linkCode = line.substr(index1, index2 - index1);
        cout << linkCode;    
        
        int relIndex;
        int nextQuoteIndex;
        
        
        relIndex = linkCode.find("rel=\"nofollow");
        if (relIndex != string::npos){
//            cout << "it's there!" << i << "\n";
            fout << linkCode + "</a>\n";
        }
        else if ((relIndex = linkCode.find("rel=\"")) != string::npos){
            nextQuoteIndex = linkCode.find("\"", relIndex+5);
            string asdf;
            asdf = linkCode.substr(relIndex, nextQuoteIndex - relIndex);
            if (asdf.length() ==  5){
//                asdf += "nofollow\"";
                linkCode.insert(relIndex + 5, "nofollow");
                linkCode += "</a>\n";
                fout <<  linkCode;
            }
            if (asdf.length() != 5)
                {
                    linkCode.insert(nextQuoteIndex, " nofollow");
                    linkCode += "</a>\n";
                    fout <<linkCode;
                }
            }
        if (((relIndex = linkCode.find("rel=\"")) == string::npos) || (relIndex == string::npos)){

            int lastanglebracket = linkCode.find(">");
            linkCode.insert(lastanglebracket, " rel=\"nofollow\"");
            fout<<linkCode + "</a>\n";

        }
            
            
        
        //else if (
        
        

    }

    
    

    
    
    
    
    
    

    return 0;
}

