803 - Page Selection by Keyword Matching

All about problems in Volume 8. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Repon kumar Roy
Learning poster
Posts: 96
Joined: Tue Apr 23, 2013 12:54 pm

Re: 803 - Page Selection by Keyword Matching

Post by Repon kumar Roy » Sat Dec 20, 2014 6:27 pm

Getting WA's
Assumed N = 8

Code: Select all


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<iterator>
#include<cassert>
#include <sstream>
#include <climits>
#include <list>
#include <string>
#include <map>
using namespace std;

/*------- Constants---- */
#define MX 31650
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define MEMSET_INF 63
#define MEM_VAL 1061109567
#define FOR(i,n) for( int i=0 ; i < n ; i++ )
#define mp(i,j) make_pair(i,j)
#define lop(i,a,b) for( int i = (a) ; i < (b) ; i++)
#define pb(a) push_back((a))
#define gc getchar_unlocked
/* -------Global Variables ------ */
ll euclid_x,euclid_y,d;

/*---- short Cuts ------- */
#define ms(ara_name,value) memset(ara_name,value,sizeof(ara_name))
typedef pair<int, int> ii;
typedef vector<int > vi ;


string str , inp;
vector<string> Pages[30];
int strength[30];


int main()
{
        
        char ch;
        int pageNumber = 1;
        int q = 0;
        
        printf("Query Pages\n");
        
        while (cin >> ch ) {
                if(ch == 'E') break;
                
                
                if( ch == 'P'){
                        getline(cin, str);
                        istringstream iss(str);
                        
                        while (iss >> inp) {
                                Pages[pageNumber].push_back(inp);

                        }
                        pageNumber ++;
                }
                if(ch == 'Q'){
                        getline(cin,str);
                        istringstream iss(str);
                        int revel = 8;
                        
                        while (iss >> inp ) {
                                
                                for (int i  =  1; i < pageNumber; i ++) {
                                        
                                        for (int j = 0; j < Pages[i].size(); j ++) {
                                                
                                                if( inp.compare(Pages[i][j]) == 0){
                                                        strength[i] += revel * (8 - j);
                                                        break;
                                                }
                                        }
                                }
                                revel --;
                        }
                        
                        int maxi = -1;
                        vector<int> ans;
                        
                        while ( maxi  ) {
                                maxi = -1;
                                int id = 0;
                                for (int i = 1 ; i < pageNumber; i ++) {
                                        if(strength[i] > maxi){
                                                maxi = strength[i];
                                                id = i;
                                        }
                                }
                                if( maxi > 0) {
                                        strength[id] = 0;
                                        ans.push_back(id);
                                }
                        }
                        
                        printf("Q%d:  ",++q);
                        for( int i = 0 ; i < ans.size() && i < 5 ; i ++) {
                                printf(" P%d",ans[i]);
                        }
                        printf("\n");
                        
                        ms(strength, 0);
                        
                        
                }
        }
        return 0;
        
}


Give me some test cases ???

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 803 - Page Selection by Keyword Matching

Post by brianfry713 » Wed Dec 24, 2014 12:22 am

For the sample input, the last line: "Q6:" shouldn't have any trailing spaces.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 8 (800-899)”