A. Spy Detected! | Round #713 Div.3
4434 단어 2021.07.262021.07.26
https://codeforces.com/contest/1512/problem/A
시간 2초, 메모리 256MB
input :
- t (1 ≤ t ≤ 100)
- n (3 ≤ n ≤ 100)
- a1, a1, …, a1 (1 ≤ ai ≤ 100)
output :
- For each test case, output a single integer — the index of the element that is not equal to others.
다른 원소들과 동일하지 않은 한 개의 원소의 인덱스를 출력하시오.
조건 :
- You are given an array a consisting of n (n≥3) positive integers. It is known that in this array, all the numbers except one are the same (for example, in the array [4,11,4,4] all numbers except one are equal to 4).
n개의 원소로 이루어진 배열이 주어집니다. 이 배열에서 단 한개의 원소만 다른 원소들과 다릅니다.
쉽게 확인할 방법이 뭐가 있을까 했는데 정렬을 한 후에 0, -1, -2의 값 3개를 이용해서 체크를 해도 될거 같고 근데 조건문이 많은거 같아서 카운팅 한 후에 1개만 나타난 것을 찾아서 출력하도록 했다.
import sys
t = int(sys.stdin.readline())
for _ in range(t):
n = int(sys.stdin.readline())
data = list(map(int, sys.stdin.readline().split()))
temp = dict()
for i in data:
if i not in temp:
temp[i] = 1
else:
temp[i] += 1
for key in temp.keys():
if temp[key] == 1:
print(data.index(key) + 1)
continue
Author And Source
이 문제에 관하여(A. Spy Detected! | Round #713 Div.3), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jsin2475/A.-Spy-Detected-Round-713-Div.3저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)