UVA 10474 Where is the Marble

来源:互联网 发布:查询域名对应的ip地址 编辑:程序博客网 时间:2024/06/06 11:29

UVA 10474 Where is the Marble?

题目大意:将给出的数字从小到大排序,并找到相应的数字是第几个

解题思路:qsort排序然后查找

#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>using namespace std;int num[10010];int num2[10010];int cmd(const void *a, const void *b) {    return *(int*)a - *(int*)b;}int main() {    int n, m, x = 0;    while(cin >> n >> m && m + n != 0) {        x++;        for(int i = 0; i < n; i++)            cin >> num[i];        for(int i = 0; i < m; i++)            cin >> num2[i];        qsort(num, n, sizeof(int), cmd);        printf("CASE# %d:\n", x);        for(int i = 0; i < m; i++) {            int a = num2[i];            int j;            for(j = 0; j < n; j++)                 if(num[j] == a)                    break;            if(j == n)                printf("%d not found\n", a);            else                printf("%d found at %d\n", a, j+1);        }    }    return 0;}
0 0
原创粉丝点击