카테고리 없음
10474 - Where is the Marble?
홍열
2012. 9. 29. 23:30
728x90
이 문제에서 왜 저딴 배경지식을 써놨는지는 모르겠다.
하지만 그냥 Sort하고 해당 값의 위치를 출력하면 끝인 문제이다.
가끔 UVA에 이런 문제가 있는 듯 하다.
input을 보면
4 1
2
3
5
1
5
인데 처음 4개가 기준 배열이고 뒤에 1개가 찾을 값이다.
해당 값이 있으면 위치 출력하고 없으면 not found 출력하면 된다.
소스코드
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int compare (const void * a, const void * b)
- {
- return ( *(int*)a - *(int*)b );
- }
- int main()
- {
- int t_case, f_case, cnt;
- bool flag = false;
- cnt = 1;
- while(cin>>t_case>>f_case)
- {
- if(t_case == 0 && f_case == 0) break;
- int *arr = new int[t_case];
- int *arr2 = new int[f_case];
- for(int i = 0; i<t_case; i++)
- {
- cin>>arr[i];
- }
- for(int i =0; i<f_case; i++)
- {
- cin>>arr2[i];
- }
- qsort (arr, t_case, sizeof(int), compare);
- cout<<"CASE# "<<cnt++<<":"<<endl;
- for(int i =0; i<f_case; i++)
- {
- flag = false;
- for(int j = 0; j<t_case; j++)
- {
- if(arr2[i] == arr[j]) {
- cout<<arr2[i]<<" found at "<<j+1<<endl;
- flag = true;
- break;
- }
- }
- if(flag == false) cout<<arr2[i]<<" not found"<<endl;
- }
- }
- return 0;
- }