ACM (UVa) : 484


Input set is only one
continue taking inputs until end of file.

Input format:
while ( cin >> n ) {
}

or,
while ( scanf (“%d”, &n) != EOF) {
}

int number [2] [10000] = {0, 0}
first row will be used to store number and respective second row for frequency of that number.

While ( cin >> n) {

if ( n is a new number, which isn’t exist already)
then, store the number at back in row 1

otherwise, // means, if exists
then, increase the frequency of that number, in row 2
}

Let, our 2-D array is:

Number

0

0

0

0

0

0

0

Frequency

0

0

0

0

0

0

0

Sample input:

3 1 2 2 1 3 5 3 2
input :: 3
not exist

Number

3

0

0

0

0

0

0

Frequency

1

0

0

0

0

0

0

Input :: 1
not exist

Number

3

1

0

0

0

0

0

Frequency

1

1

0

0

0

0

0

Input :: 2
not exist

Number

3

1

2

0

0

0

0

Frequency

1

1

1

0

0

0

0

Input :: 2
already exist

Number

3

1

2

0

0

0

0

Frequency

1

1

2

0

0

0

0

Input :: 1
already exist

Number

3

1

2

0

0

0

0

Frequency

1

2

2

0

0

0

0

Input :: 3
already exist

Number

3

1

2

0

0

0

0

Frequency

2

2

2

0

0

0

0

Input :: 5
not exist

Number

3

1

2

5

0

0

0

Frequency

2

2

2

1

0

0

0

Input :: 3
already exist

Number

3

1

2

5

0

0

0

Frequency

3

2

2

1

0

0

0

Input :: 3
already exist

Number

3

1

2

5

0

0

0

Frequency

4

2

2

1

0

0

0

Input :: 2
already exist

Number

3

1

2

5

0

0

0

Frequency

4

2

3

1

0

0

0

Sample output :
3 4
1 2
2 3
5 1
// have to follow the input sequence

Critical input:
1 -1 2 1 8 9 -3 -4 2 6 3 -3 -1 5 2 6 8 -8 -4 -6 -7 -1

Critical output:
1 2
-1 3
2 3
8 2
9 1
-3 2
-4 2
6 2
3 1
5 1
-8 1
-6 1
-7 1

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