toj_2999.cpp

来自「Tianjin University Online Judge 的80多道题目 」· C++ 代码 · 共 87 行

CPP
87
字号
#include<cstdio>#include<cstring>#include<cstdlib>#include<iterator>#include<vector>#include<algorithm>using namespace std;#define MAXWORD 11#define MAXWORDLEN 22#define MAXTITLE 1010struct TITLE{    char word[ MAXWORD ][ MAXWORDLEN ];    int nW;    int k;} request;//titleBack[ MAXTITLE ], title[ MAXTITLE ] , request;vector < struct TITLE > titleBack[ MAXTITLE ];vector < struct TITLE > title[ MAXTITLE ];int n , m;int wordCmp( const void *a , const void *b ){    return strcmp( ( char* ) a , ( char * ) b );}bool titleCmp( TITLE * a , TITLE * b ){    return a->k - b->k;}    int main(){    int i , j , k ;    char endCh;    bool found;    while( scanf( "%d" , &n ) != EOF && n ){        for( i = 0; i < n; i++ ){            for( title[ i ].nW = 0; scanf( "%s%c" , title[ i ].word[ title[ i ].nW++ ] , &endCh ) && endCh != '\n' ; );            scanf( "%d" , &title[ i ].k );        }        stable_sort( title , title + n , titleCmp );        memcpy( titleBack , title , sizeof( title ) );        for( i = 0; i < n; i++ )            qsort( &title[ i ].word , title[ i ].nW , MAXWORDLEN , wordCmp );        scanf( "%d" , &m );        for( i = 0; i < m; i++ )            for( request.nW = 0; scanf( "%s%c" , request.word[ request.nW++ ] , &endCh ) && endCh != '\n' ; );        for( i = 0; i < n; i++ ){            found = true;            for( j = 0; j < request.nW; j++ )                if( bsearch( request.word[ j ] ,  &title[ i ].word , title[ i ].nW , MAXWORDLEN , wordCmp ) ==NULL  ){                    found = false;                    break;                }            if( found ){                for( j = 0; j < title[ i ].nW; j++ ){                    printf( "%s" , titleBack[ i ].word[ j ] );                    if( j != title[ i ].nW - 1 )                        printf( " " );                    else                        printf( "\n" );                }            }        }    }    return 0;}                                                                                                                                                                            

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?