UVa 10474 Where is the Marble?
来源:互联网 发布:淘宝女装店铺名称 编辑:程序博客网 时间:2024/06/06 04:39
挺简单的一道题,直接AC
用的是insert sorting方法,效率并不高,用时比较长
#include<iostream>#include<cstring>void sorting(int* in, int N);using namespace std;const int maxn = 10004;int in[maxn], fi[maxn];int main(){int N, Q;int count = 1;while (cin >> N >> Q&&N != 0){memset(in, 0, sizeof(in));memset(fi, 0, sizeof(fi));for (int i = 0; i < N; i++)cin >> in[i];for (int i = 0; i < Q; i++)cin >> fi[i];sorting(in, N);/*for (int i = 0; i < N; i++)cout << in[i];*/cout << "CASE# " << count << ':' << endl; for (int i = 0; i < Q; i++){int ans = 0;int j = 0;for (; j < N; j++) if (fi[i] == in[j]){ans = 1;break;}if (ans == 0)cout << fi[i] << " not found" << endl;else cout << fi[i] << " found at " << j + 1 << endl;}count++;}}void sorting(int* in, int N){int key = in[1];for (int i = 1; i < N; i++){int j = i-1;while (key <= in[j] && j >= 0){in[j + 1] = in[j];j--;}in[j+1] = key;key = in[i+1];}}
阅读全文
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
- shiro(1)
- js小点-EL表达式的js函数传参问题-js控制<a>href跳转问题
- Setvlet(补充)(理论、创建、实现方式、功能)
- NGUI层级中间的特效显示
- Rails 中的Concerns 目录
- UVa 10474 Where is the Marble?
- spring定时任务
- 浅谈用对拍验证程序正确性
- 算法概论习题解答8.22
- Maven POM.xml 标签详解
- POJ3616-递推-Milking Time
- LeetCode(1)--TwoSum
- [BZOJ 4152] The Captain 最短路(Dijkstra版)
- JS中element对象与Node对象常用基础知识