Created
March 6, 2016 14:49
-
-
Save quickgrid/e4d05862056cfede593d to your computer and use it in GitHub Desktop.
It show the parent child relation of html tags ( or anything else on space based hierarchy )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: Asif Ahmed | |
* Site: https://quickgrid.blogspot.com | |
* Problem: Parse a text file and show details of hierarchial relation between the lines. | |
* Technique: It show the parent child relation of html tags ( or anything else on space based hierarchy ) | |
*/ | |
#include<iostream> | |
#include<string> | |
#include<cstdio> | |
#include<cstring> | |
using namespace std; | |
string tags[128]; | |
int main(){ | |
freopen("input.txt", "r", stdin); | |
//freopen("output.txt", "w", stdout); | |
string s; | |
int tagCount = 0; | |
while( getline(cin, s) ){ | |
tags[tagCount++] = s; | |
} | |
for( int i = 0; i < tagCount; ++i ){ | |
int k = 0; | |
for(; k < tags[i].length(); ++k ){ | |
if( tags[i][k] != ' ' ) | |
break; | |
} | |
for( int j = i + 1; j < tagCount; ++j ){ | |
if( tags[j][k] == ' ' ){ | |
int x = k; | |
for(; x < tags[j].length(); ++x ){ | |
if( tags[j][x] != ' ' ) break; | |
} | |
cout << tags[j] << " is the " << (x - k) << " th child of " << tags[i] << "\n"; | |
}else{ | |
break; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment