Algorithm


Problem Name: 2 AD-HOC - URI Online Judge | 2189

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2189

Kermesse

 

Por OBI - Olimpíada Brasileira de Informática 2000 BR Brazil

Timelimit: 1

The senior students decided to organize a bazaar to raise funds for the graduation party. The party promised to be a success, because the father of one of the trainees, Theophilus, who owns a computer store, decided to donate a computer to be raffled among those who attend. Students prepared mulled wine stalls, popcorn, candy, rehearsed the gang and put on sale tickets numbered sequentially from 1. The ticket number would serve to draw the computer. It was agreed that Theophilus would decide the draw method; in principle the draw would be, of course, computerized.

The venue for the party was the school gym. The entrance of the participants was the main door, which has a wheel where a person spends at a time. At the entrance, an employee entered in a list in school computer, the ticket number, in order of arrival of the participants. After the input of all participants, Theophilus began working on the computer to prepare the draw. Checking the list of gifts, he noticed a notable feature: there was only one case in the entire list, the participant that had the numbered ticket with i, was the ith person to enter the gym. Theophilus was so delighted by the coincidence that decided that the draw would not be necessary: this person would be the winner of the computer.

Knowing the list of participants, in order of arrival, your task is to determine the winning ticket number, knowing that the winner is the only participant who has the ticket number equal to its input position in the party.

 

Input

 

The input consists of several test sets. The first line of a test set contains a positive integer N (0 ≤ N ≤ 10000) that indicates the number of partygoers. The next line contains the following, in order of entry, ofN tickets of people who attended the party. The end of input is indicated when N = 0. For each input test set there will be a single winner.

 

Output

 

For each input test set your program should produce three lines. The first line identifies the test set, in the form "Teste n", onde n is numbered from 1. The second line should contain the winning ticket number, as determined by your program. The third line should be left blank. The spelling shown in Example output below should be followed strictly.

 

 

 

Input Sample Output Sample

4

4 5 3 1

10

9 8 7 6 1 4 3 2 12 10

0

Teste 1

3


Teste 2

10

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <:cstdio>
int main() {
    int i, n, vez = 1;
    while (1) {
        scanf("%d", &n);
        if (n == 0)
            break;
        else {
            printf("Teste %d\n", vez);
            int resp = 0;
            for (i = 0; i  <  n; i++) {
                int davez;
                scanf("%d", &davez);
                if (resp == 0 && i + 1 == davez) resp = davez;
            }
            printf("%d\n\n", resp);
        }
        vez++;
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
4 5 3 1
10
9 8 7 6 1 4 3 2 12 10
0

Output

x
+
cmd
Teste 1
3

Teste 2
10

#2 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("fs")

const input = readFileSync("/dev/stdin", "utf8")
	.split("\n")
	.map(line => line.split(" ").map(value => Number.parseInt(value, 10)))

function main() {
	const responses = []

	for (let i = 0, testcase = 1; i  <  input.length; i += 2, testcase += 1) {
		if (input[i][0] === 0)
			break

		const position = input[i + 1].find((value, index) => value === index + 1)

		responses.push(
			`Teste ${testcase}`,
			position,
			""
		)
	}

	console.log(responses.join("\n"))
}

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
4 5 3 1
10
9 8 7 6 1 4 3 2 12 10
0

Output

x
+
cmd
Teste 1
3

Teste 2
10
Advertisements

Demonstration


Previous
#2188 Beecrowd Online Judge Solution 2188 Capuchin Monkey Solution in C, C++, Java, Js and Python
Next
#2191 Beecrowd Online Judge Solution 2191 Goal Difference Solution in C, C++, Java, Js and Python