1610 - Party Games

All about problems in Volume 16. 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: 1610 - Party Games

Post by Repon kumar Roy » Sun Mar 01, 2015 8:49 pm

I am getting WA....

Code: Select all

#include <bits/stdc++.h>
using namespace std;

/*------- Constants---- */
#define LMT                      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
#define PI                      acos(-1.0)
#define inf                     1<<30
#define lc                      ((n)<<1)
#define rc                      ((n)<<1 |1)
#define GREATER(x, y)           ((x) > (y) + EPS)
#define GREATER_EQUAL(x, y)     ((x) > (y) - EPS)
#define LESS(x, y)              ((x) < (y) - EPS)
#define LESS_EQUAL(x, y)        ((x) < (y) + EPS)
#define EQUAL(x, y)             (abs((x) - (y)) < EPS)
#define sc(x)                   scanf("%d",&x)
/* -------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 ;
/*------ template functions ------ */
template <class T> inline T bigmod(T p,T e,T M){
        ll ret = 1;
        for(; e > 0; e >>= 1){
                if(e & 1) ret = (ret * p) % M;
                p = (p * p) % M;
        } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/*************************** END OF TEMPLATE ****************************/

vector < string > word;
string a;
int main()
{
	
	int n ;
        while (scanf("%d",&n) == 1 && n ) {
                lop(i, 0, n) {
                        cin >> a;
                        word.push_back(a);
                }
                sort(word.begin(), word.end());
                
                int flag= 0;
                int target = n / 2  -1 ;
                for (int i = 0 ; i < word[target] .size() ; i ++ ) {
                        if( word [target] [i] != word[target + 1][i]) {
                                for (int j = 0; j < i ; j ++ ) {
                                        printf("%c",word[target][j]) ;
                                }
                                
                                flag = 1;
                                
                                int k1 = word[target ][i] + 1;
                                int k2 = word[target + 1][i];
                                int k3 = 10000;
                                if( word[target].size() - 1 == i ) k3 = word[target][i];
                                printf("%c", min (min(k1,k2) , k3 ));
                                printf("\n");
                                break;
                        }
                }
                if( flag == 0) printf("%s\n", word[target].c_str());
                word.clear();
        }
	return 0;
}

Give me some TestCases...

Post Reply

Return to “Volume 16 (1600-1699)”