uva 10474

本文提供了一段解决UVa 10474问题的C++代码示例,该代码实现了从输入中读取整数并对其进行排序的功能。随后程序会查找用户指定的查询值,并输出其在排序列表中的位置或指示未找到的消息。适用于初学者理解搜索和排序的基本概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简单题.. 权当打打字

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring> 
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
const int MAXN = 10 + 5;
const int SLEEP = 0;
const int AWAKE = 1;
typedef long long LL;

/*
uva 10474
 
*/

int main(){
//	freopen("input2.txt","r",stdin);
	int N,Q,Case = 0; 
	while( scanf("%d %d",&N,&Q) && !(N==0&&Q==0) ){
		vector<int> list;
		int t;
		for(int i=0; i<N; i++){
			cin >> t;
			list.push_back(t);
		}
		sort(list.begin(),list.end());
		
		printf("CASE# %d:\n",++Case);
		for(int i=0; i<Q; i++){
			int ans = -1;
			cin >> t;
			for(int j=0; j<list.size(); j++){
				if( t==list[j] ){
					ans = j+1;
					break;
				}
			}
			printf("%d ",t);
			if( ans>0 ){
				printf("found at %d\n",ans);
			}else{
				printf("not found\n");
			}
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值