CodeChef : Discrepancies in the Voters List (VOTERS)



// http://www.codechef.com/problems/VOTERS/
// Runtime : 0.52s
// Tag : Sort, Merge Sort

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;


int main ()
{
	int n1, n2, n3;
	scanf ("%d %d %d", &n1, &n2, &n3);

	vector <int> v;
	int input;

	for ( int i = 0; i < n1; i++ ) {
		scanf ("%d", &input);
		v.push_back (input);
	}

	for ( int i = 0; i < n2; i++ ) {
		scanf ("%d", &input);
		v.push_back (input);
	}

	for ( int i = 0; i < n3; i++ ) {
		scanf ("%d", &input);
		v.push_back (input);
	}

	sort (v.begin (), v.end ());

	int in = 0;
	vector <int> output;

	while ( in < v.size () - 1 ) {
		if ( v [in] == v [in + 1] ) {
			output.push_back (v [in]);
			in += 2;

			if ( in != v.size () && v [in - 1] == v [in] ) in++;
		}
		else in++;
	}

	printf ("%d\n", output.size ());

	for ( int i = 0; i < output.size (); i++ ) printf ("%d\n", output [i]);


	return 0;
}

// @END_OF_SOURCE_CODE

One thought on “CodeChef : Discrepancies in the Voters List (VOTERS)

  1. 
    // Runtime : 0.50s
    // using integer array 
    
    
    // @BEGIN_OF_SOURCE_CODE
    
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <cctype>
    #include <stack>
    #include <queue>
    #include <list>
    #include <vector>
    #include <map>
    #include <sstream>
    #include <cmath>
    #include <bitset>
    #include <utility>
    #include <set>
    #include <numeric>
    #define INT_MAX 2147483647
    #define INT_MIN -2147483647
    #define pi acos(-1.0)
    #define N 50000
    #define LL unsigned long long
    using namespace std;
    
    
    int main ()
    {
    	int n1, n2, n3;
    	scanf ("%d %d %d", &n1, &n2, &n3);
    
    	int v [N + N + N];
    
    	for ( int i = 0; i < n1; i++ ) scanf ("%d", &v [i]);
    
    	for ( int i = 0; i < n2; i++ ) scanf ("%d", &v [n1 + i]);
    
    	for ( int i = 0; i < n3; i++ ) scanf ("%d", &v [n1 + n2 + i]);
    
    	int tot = n1 + n2 + n3;
    
    	sort (v, v + tot);
    
    	int in = 0;
    	int output [N + N + N];
    	int cnt = 0;
    
    	while ( in < tot - 1 ) {
    		if ( v [in] == v [in + 1] ) {
    			output [cnt] = v [in];
    			cnt++;
    			in += 2;
    
    			if ( in != tot && v [in - 1] == v [in] ) in++;
    		}
    		else in++;
    	}
    
    	printf ("%d\n", cnt);
    
    	for ( int i = 0; i < cnt; i++ ) printf ("%d\n", output [i]);
    
    
    	return 0;
    }
    
    // @END_OF_SOURCE_CODE
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s