We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
structdocumentget_document(char*text){structdocumentdoc;structparagraph*cur_paragraph=NULL;structsentence*cur_sentence=NULL;char*new_word=NULL;doc.data=NULL;doc.paragraph_count=0;for(char*s=text;*s;++s){if(*s==' '||*s=='.'){// nouveau paragrapheif(cur_paragraph==NULL){doc.paragraph_count++;doc.data=(structparagraph*)realloc(doc.data,sizeof(structparagraph)*doc.paragraph_count);cur_paragraph=doc.data+doc.paragraph_count-1;cur_paragraph->data=NULL;cur_paragraph->sentence_count=0;cur_sentence=NULL;// on recommence de facto une phrase}// nouvelle phraseif(cur_sentence==NULL){cur_paragraph->sentence_count++;cur_paragraph->data=(structsentence*)realloc(cur_paragraph->data,sizeof(structsentence)*cur_paragraph->sentence_count);cur_sentence=cur_paragraph->data+cur_paragraph->sentence_count-1;cur_sentence->data=NULL;cur_sentence->word_count=0;}// nouveau motcur_sentence->word_count++;cur_sentence->data=(structword*)realloc(cur_sentence->data,sizeof(structword)*cur_sentence->word_count);cur_sentence->data[cur_sentence->word_count-1].data=new_word;new_word=NULL;if(*s=='.')cur_sentence=NULL;// on recommencera une phrase*s=0;}elseif(*s=='\n'){cur_sentence=NULL;cur_paragraph=NULL;}else{if(new_word==NULL){new_word=s;}}}returndoc;}structwordkth_word_in_mth_sentence_of_nth_paragraph(structdocumentDoc,intk,intm,intn){returnDoc.data[n-1].data[m-1].data[k-1];}structsentencekth_sentence_in_mth_paragraph(structdocumentDoc,intk,intm){returnDoc.data[m-1].data[k-1];}structparagraphkth_paragraph(structdocumentDoc,intk){returnDoc.data[k-1];}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Structuring the Document
You are viewing a single comment's thread. Return to all comments →