UVA-10474 Where is the Marble?
来源:互联网 发布:centos selenium 编辑:程序博客网 时间:2024/06/04 18:59
2016-07-19
UVA - 10474 Where is the Marble?
题目大意:输入 N 和 Q,接下去输入 N 个数和 Q 个数,求这 Q 个数分别是 N 中从小到大数的第几个,如果不在 N 中,输出 not found。
解题思路:题意看懂后很好A的,排序后判断。
#include <iostream>#include <stdlib.h>#include <cstdio>#include <cstring>using namespace std;int N;int Q;int n[10000];int q[10000];int flag;int num = 0;int cmp(const void *a , const void *b) { return ( *(int*)a - *(int*)b );}int main() { while ( scanf("%d%d",&N,&Q) && N != 0 && Q != 0 ) { cout << "CASE# " << ++num << ":" << endl; memset( n , 0 , sizeof(n) ); memset( q , 0 , sizeof(q) ); for (int i = 0; i < N; i++) scanf("%d", &n[i]); for (int i = 0; i < Q; i++) scanf("%d", &q[i]); qsort( n , N , sizeof(n[0]) , cmp ); for (int i = 0; i < Q; i++) { flag = 0; for (int j = 0; j < N; j++) { if ( q[i] == n[j] ) { cout << q[i] << " found at " << j + 1 << endl; flag = 1; break; } } if ( !flag ) cout << q[i] << " not found" << endl; } } return 0;}
0 0
- UVa 10474 Where is the Marble?
- Uva 10474 Where is the Marble?
- uva 10474 Where is the Marble?
- UVA 10474 Where is the Marble?
- UVA 10474 - Where is the Marble
- uva-10474 - Where is the Marble?
- uva 10474 - Where is the Marble?
- UVA 10474 - Where is the Marble?
- UVa 10474 - Where is the Marble?
- UVa 10474 - Where is the Marble
- UVa 10474 - Where is the Marble?
- UVA 10474 Where is the Marble?
- UVA 10474 - Where is the Marble
- UVa - 10474 - Where is the Marble?
- uva 10474 Where is the Marble?
- uva 10474 Where is the Marble?
- uva - 10474 - Where is the Marble?
- uva 10474 - Where is the Marble
- 题目1043:Day of Week
- tomcat从下载到使用
- linux下安装配置jenkins
- 《剑指offer》字符串的排列
- 81. Search in Rotated Sorted Array II
- UVA-10474 Where is the Marble?
- 青蛙跳台阶问题
- POJ 2369Permutations
- hdoj--1862 EXCEL排序(sort+结构体)
- * **ACM错误总结
- restful--spring
- linux常用的一些命令(一)
- 【杭电-oj】-2803-The MAX(sort快排)
- UVA-152 Tree's a Crowd