Exemplo n.º 1
0
int mpeg3_read_toc(mpeg3_t *file)
{
	char string[MPEG3_STRLEN];
	int version;

/* Test version number */
	mpeg3io_seek(file->fs, 0);
	fscanf(file->fs->fd, "%s %d", string, &version);
	if(version != TOCVERSION && version != TOCVIDEO) return 1;
	switch(version)
	{
		case TOCVIDEO:
			file->is_video_stream = 1;
			break;
	}

/* Read titles */
	read_titles(file->demuxer, version);
	return 0;
}
Exemplo n.º 2
0
/// MAIN
int main(){
	std::ios_base::sync_with_stdio(false);

	// DEBUG: Redirection of stdin
  //  std::ifstream in( "/home/draxent/Scrivania/Contests/UVa/123/input2.txt" );
  //  std::cin.rdbuf( in.rdbuf() );

  // Read the words to ignore and sort them
  std::vector<std::string> words_ignore = read_words_ignore();
  std::sort( words_ignore.begin(), words_ignore.end() );

  // DEBUG: Print the word to ignore
  //  for ( const std::string& word : words_ignore )
  //    std::cout << word << ", ";
  //  std::cout << std::endl << std::endl;

  // Vector that stores all the keywords of the list of titles
  std::vector<RefTitleWord> keywords;
  // Read the titles (variable unused but its contents it is used indirectly trough keywords)
  std::vector<std::vector<std::string>> titles = read_titles( words_ignore, keywords );

  // DEBUG: Print the titles
  //  for ( const std::vector<std::string>& words : titles ){
  //    std::cout << (&words - &titles[0]) << ") ";
  //    for( const std::string& word : words )
  //      std::cout << word << " ";
  //    std::cout << std::endl;
  //  }
  //  std::cout << std::endl;

  // Sort the keywords
  std::sort( keywords.begin(), keywords.end(), [](const RefTitleWord& a, const RefTitleWord& b) {
    // Compare the two keyword string
    int res = strcmp( a.word->c_str(), b.word->c_str() );
    // If they are not equal return the comparison, otherwise respect the original order of the titles
    // If a title as more the an equal keyword, respect the order of the words inside the title
    if ( res == 0 ){
      if ( a.title == b.title ) return (a.word < b.word);
      else return (a.title < b.title);
    }
    else return (res < 0);
  });

  // DEBUG: Print the keywords
  //  for( const RefTitleWord& ref : keywords )
  //    std::cout << "(" << *ref.word << "," << (ref.title - &titles[0]) << "," << (ref.word - &(*ref.title)[0]) << "); ";
  //  std::cout << std::endl << std::endl;

  for( const RefTitleWord& ref : keywords ){
    for( const std::string& word : *(ref.title) ){
      // Check if the current word is equal of the keyword
      if ( &word == ref.word ){
        // Convert the keyword in uppercase and print it
        std::string uppercase;
        uppercase.resize(word.size());
        std::transform( word.begin(), word.end(), uppercase.begin(), toupper );
        std::cout << uppercase;
      }
      else
        std::cout << word;
    }
    std::cout << std::endl;
  }

  return 0;
}