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.
// Initialise and allocate.
initialise_document(text);
return Doc;
}
struct word kth_word_in_mth_sentence_of_nth_paragraph(struct document Doc, int k, int m, int n) {
if (k < 1 || k > Doc.paragraph_count) {
printf("Paragraph index out of bounds\n");
exit(1);
}
if (m < 1 || m > Doc.data[k-1].sentence_count) {
printf("word index out of bounds\n");
exit(1);
}
if (n < 1 || n > Doc.data[k-1].data[n-1].word_count) {
printf("word index out of bounds\n");
exit(1);
}
return Doc.data[k-1].data[m-1].data[n-1];
}
struct sentence kth_sentence_in_mth_paragraph(struct document Doc, int k, int m) {
if (k < 1 || k > Doc.paragraph_count) {
printf("Paragraph index out of bounds\n");
exit(1);
}
if (m < 1 || m > Doc.data[k-1].sentence_count) {
printf("Sentence index out of bounds\n");
exit(1);
}
return Doc.data[k-1].data[m-1];
}
struct paragraph kth_paragraph(struct document Doc, int k) {
if(k >= 1 || k <= Doc.paragraph_count){
return Doc.data[k-1];
}
else{
printf("k is out of bound");
exit(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 →
struct document Doc = {0};
void initialise_document(char *text){
char text_buffer[MAX_CHARACTERS]; strcpy(text_buffer, text); int p_count = 0;
// for each paragraph sentence count
}
struct document get_document(char* text) {
}
struct word kth_word_in_mth_sentence_of_nth_paragraph(struct document Doc, int k, int m, int n) {
}
struct sentence kth_sentence_in_mth_paragraph(struct document Doc, int k, int m) { if (k < 1 || k > Doc.paragraph_count) { printf("Paragraph index out of bounds\n"); exit(1); }
}
struct paragraph kth_paragraph(struct document Doc, int k) { if(k >= 1 || k <= Doc.paragraph_count){ return Doc.data[k-1]; } else{ printf("k is out of bound"); exit(1); } }