ACM (TJU) : 3108


#include
#include
using namespace std;

int a [5000];
int x;

bool find ( int k)
{
for ( int i = 0; i < x; i++ ) { if ( a [i] == k ) return true; } return false; } int main () { int testCase; scanf ("%d", &testCase); while ( testCase-- ) { int b [5000]; int y; scanf ("%d %d", &x, &y); int i; for ( i = 0; i < x; i++ ) scanf ("%d", &a [i]); for ( i = 0; i < y; i++ ) scanf ("%d", &b [i]); sort (a, a + x); sort (b, b + y); bool flag = true; bool space = false; for ( i = 0; i < y; i++ ) { if ( flag ) { flag = false; if ( find (b [i]) ) { printf ("%d", b [i]); space = true; } } else { if ( b [i] != b [i - 1] && find (b [i]) ) { if ( space ) printf (" "); printf ("%d", b [i]); space = true; } } } printf ("\n"); } return 0; } [/sourcecode]

Advertisements

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