ZOJ 3492 模拟循环链表线性查找
WA了好几次最后找到错因是因为数组开小了! = =
string whose length never exceeds 20
所以至少要开到21 = = ,我却一直开20 ╮(╯▽╰)╭
AC代码:
#include <stdio.h>
#include <string.h>
int main(){
int t,n,i,j,flag;
char target[],name[][];
scanf("%d",&t);
while(t--){
scanf("%d%s",&n,target);
for(i=;i<n;i++)
scanf("%s",name[i]);
for(i=;i<n;i++)
if(strcmp(name[i],target) == ) break;
flag = (i + n/)%n;
printf("%s\n",name[flag]);
}
return ;
}
Kagome Kagome
Time Limit: 2 Seconds Memory Limit: 65536 KB
Kagome kagome, kago no naka no tori wa
Itsu itsu deyaru? Yoake no ban ni
Tsuru to kame to subetta.
Ushiro no shoumen daare?
Translation:
Kagome kagome, the bird in the cage,
when will you come out?
In the evening of the dawn,
the crane and turtle slipped.
Who stands right behind you now?
Kagome Kagome is a Japanese children's game. One child is chosen as the oni (literally demon or ogre, but similar to the concept of "it" in tag) and sits blindfolded (or with their eyes covered). The other children join hands and walk in circles around the oni while singing the song for the game. When the song stops, the oni speaks aloud the name of the person behind him, and if he is correct, the person behind will exchange places with the oni.
Higurashi Tewi is playing Kagome Kagome with her n (n is even) friends as the oni now. She peeps to know who is right in front of her. Knowing the order of the children in circle and assuming that they keep distance evenly, it's easy to derive who is right behind her.
Input
There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.
The first line of each test case starts with an even number 1 ≤ n ≤ 100, followed by the name of the child who is right in front of Higurashi Tewi. The second line contains exactly n different names, listed in counterclockwise order. Name is an alphanumeric string whose length never exceeds 20. It's guaranteed that the child in front of Higurashi Tewi is always contained in the list exactly once.
Output
For each test case, output the name of the child who is right behind Higurashi Tewi.
Sample Input
3
2 Alice
Alice Bob
4 inu
inu neko usagi kizune
4 cat
dog cat rabbit fox
Sample Output
Bob
usagi
fox
ZOJ 3492 模拟循环链表线性查找的更多相关文章
- List<T>线性查找和二分查找BinarySearch效率分析
今天因为要用到List的查找功能,所以写了一段测试代码,测试线性查找和二分查找的性能差距,以决定选择哪种查找方式. 线性查找:Contains,Find,IndexOf都是线性查找. 二分查找:Bin ...
- 数组查找算法的C语言 实现-----线性查找和二分查找
线性查找 Linear Search 用户输入学生学号的成绩 二分查找 Binary Search 要求数据表是已经排好序的 程序存在小的瑕疵
- C++泛型线性查找算法——find
C++泛型线性查找算法--find <泛型编程和STL>笔记及思考. 线性查找可能是最为简单的一类查找算法了.他所作用的数据结构为一维线性的空间.这篇文章主要介绍使用 C++ 实现泛型算法 ...
- 算法之二分查找PK线性查找
列表查找(线性查找) 本质就是列表的index() 顺序查找 也叫线性查找,从列表第一个元素开始,顺序进行搜索,知道找到元素或搜索到列表最后一个元素为止. 以下是示例代码: def line_sear ...
- 复习下C 链表操作(单向循环链表、查找循环节点)
循环链表 稍复杂点. 肯能会有0 或 6 字型的单向循环链表. 接下来创建 单向循环链表 并 查找单向循环链表中的循环节点. 这里已6字型单向循环链表为例. //创建 循环链表 Student * ...
- java数组回顾---线性查找最大值最小值---二分查找
import java.util.Scanner; public class ArrayDemo { public static void main(String []args) { //------ ...
- 算法:线性查找(重点isFlag标志)
package com.atguigu; public class Main { public static void main(String[] args) { String[] arr=new S ...
- 【PHP数据结构】线性查找与二分查找
欢迎来到查找的世界,在学习完各种数据结构之后,总算走到了这一步,不知道大家有什么感想呢?反正我是边学边忘,现在让我去说说图的那几个算法还是在蒙圈的状态中.不过学习嘛,就是一步一步的来,暂时搞不懂的东西 ...
- BFPRT(线性查找算法)
BFPRT算法解决的问题十分经典,即从某n个元素的序列中选出第k大(第k小)的元素,通过巧妙的分 析,BFPRT可以保证在最坏情况下仍为线性时间复杂度.该算法的思想与快速排序思想相似,当然,为使得算法 ...
随机推荐
- hadoop权威指南 chapter1 Meet Hadoop
Meet Hadoop 1.1 Data!(数据) Most of the data is locked up in the largest web properties (like search e ...
- Windows 无法启动xx服务 错误1053:服务没有及时响应启动或控制请求
症状:win7系统的很多系统关键服务,启动不了,双击该服务也弹不了操作框,系统服务是设置为自动 的,但是就是启动不了,在本地服务窗口中只能启动该服务,但是双击会弹不了窗口,你点启动后会出现错误提示10 ...
- 在 Windows系统中编译node.js 源代码
Node.js 在 Windows 下只能通过 Microsoft Visual Studio 编译,因此你需要首先安装 Visual Studio 或者免费的 Visual Studio Expre ...
- [条款36]绝不重新定义继承而来的non-virtual函数
看下面的两个类的声明代码: class B { public: void mf(); //something to do }; class D : public B { public: void mf ...
- 如何使用SublimeText风格的代码高亮样式 添加Zed Coding(EMMET)插件
因为觉得博客园自带的代码高亮样式很单一,不符合作为前端的我的审美习惯,于是下定决心要想办法折腾出一个方法来应用上另外一套代码高亮样式. 虽然探索的过程是很痛苦的,但最后还是成功了,但也不枉付出的那些努 ...
- awk参数详解
wk是行处理器: 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息 awk处理过程: 依次对每一行进行处理,然后输出 awk命令形式: awk [-F| ...
- 更改firefox默认搜索引擎
使用Organizie Search Engines 这个插件 这个插件似乎不能添加搜索引擎 但是可以修改搜索引擎 好吧 由于有时候firefox会自动更新搜索引擎 所以不要对Google搜索引擎 ...
- 无法将类型“ASP.login_aspx”转换为“System.Web.UI.WebControls.Login”
今天碰上了一个很傻的问题,起码我认为是这样. 项目中首页名是:Login.aspx,编译.运行都没有出现问题. 于是打包发布网站,各项内容都配置好后,问题出现了.一运行首页面就出现下面这个错误: 编译 ...
- 启动(Startup)
Startup Chrome是一个单一的可执行程序.它清楚如何运行其它进程. 下面是chrome启动的概述: 1. 首先,chrome有一个平台相关的入口点:在windows上是wWinMain(): ...
- Xamarin.Android开发实践(一)
原文:Xamarin.Android开发实践(一) 一.准备工作 1.创建一个空的解决方案,并命名为Phoneword 2.右击解决方案 新建->新建项目 并命名为Phoneword_Droid ...