-
Codeforces Round #488 by NEAR (Div. 2) - A. Fingerprints구현(Implementation) 2018. 6. 20. 15:53반응형
http://codeforces.com/contest/994/problem/A
1. 문제
A. Fingerprintstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
InputThe first line contains two integers and () representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains distinct space-separated integers () representing the sequence.
The next line contains distinct space-separated integers () — the keys with fingerprints.
OutputIn a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
2. 알고리즘
숫자키와 지문 배열을 입력 받는다.
지분 배열이 요소와 숫자키 배열에 요소를 0 번 인덱스 부터 비교 한다.
지문 배열의 요소와 숫자키 배열의 요소가 같은 게 만나면 현재 요소를 출력 한다.
출력 이후에는 -1로 초기화 한다.
위에 작업을 지문배열이 -1 이 될 때까지 반복 한다.
3. 코드
123456789101112131415161718192021222324252627282930313233343536373839#include <iostream>#include <sstream>#include <string>#include <algorithm>#include <functional>#include <vector>#include <list>#include <queue>#include <map>#include <set>#include <stack>using namespace std;int main() {std::ios::sync_with_stdio(false); cin.tie(0);int n, k; cin >> n >> k;int key[11] = {-1, };int finger[11] = {-1, };for(int i=0; i<n; i++)cin >> key[i];for(int i=0; i<k; i++)cin >> finger[i];for (int i=0; i<n; i++) {for (int j=0; j<k; j++) {if (key[i] == finger[j]) {cout << key[i] << " ";finger[j] = -1;}}}return 0;}cs 반응형'구현(Implementation)' 카테고리의 다른 글
백준 4344번: 평균은 넘겠지 (0) 2018.07.03 백준 2526번: 싸이클 (0) 2018.06.23 백준 1225번: 이상한 곱셈 (0) 2018.06.20 백준 10250번 : ACM 호텔 (0) 2018.06.20 백준 1011번 : Fly me to the Alpha Centauri (0) 2018.06.20