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可以保证在最坏情况下仍为线性时间复杂度.该算法的思想与快速排序思想相似,当然,为使得算法 ...
随机推荐
- PHP程序猿必须学习的第二课——站点安全问题预防
作为PHP程序猿.第一课我们学习了基本的语法.那么在熟悉基本的语法之后我们应该学些什么呢?我觉得是安全问题.安全问题基于一个站点宛如基石,一着不慎,意味着灾难性的事故. 这里主要就提三点最简单,也是最 ...
- PeopleEditor的取值及赋值
/// <summary> /// 从PeopleEditor取值 /// </summary> /// <param name="peopleEditor&q ...
- View从Action中获得数据和html helper function(转载)
@model MvcApplication1.Models.M_Person @using MvcApplication1.Models; @{ ViewBag.Title = "GetDa ...
- OD调试篇3-小软件破解1
OD调试篇3-小软件破解1 要求如下图该软件需要改5个地方,其中1.2是软件未注册而设定限定的添加个数,3.4.5是软件显示的一些未注册的信息. 一. 1.按1运行程序,添加用户添加第五个时出现提示, ...
- 杭电ACM 素数判定
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- php的迭代器
接口Iterator 主要需要实现的方法: abstract public mixed current ( void ) abstract public scalar key ( void ) abs ...
- 转: css实现垂直居中的方法
利用 CSS 来实现对象的垂直居中有许多不同的方法,比较难的是选择那个正确的方法.我下面说明一下我看到的好的方法和怎么来创建一个好的居中网站. 用 CSS 实现垂直居中并不容易.有些方法在一些浏览器中 ...
- QtInternal 之 高效使用QString(使用QLatin1String,QStringRef,QStringBuilder,QStringMatcher等相关类)
注意:本文翻译自 http://developer.qt.nokia.com 中的 UsingQStringEffectively ,中文译文见 简体中文版 ,如果你对翻译wiki感兴趣 ...
- python概要
python与r语言接口Rpy,统计 科学计算,数值拟合:numpy,scipy 可视化2d:matplotlib,Pylab 可视化3d:mayaviz 复杂网络:networkx 交互终端: bs ...
- VC++中的DDX和DDV
DDX/DDV 通过使用ClassWizard向对话类添加成员变量,你可以利用ClassWizard所提供的高效特征,为对话数据交换和对话数据验证自动生成源代码,也就是人们所熟知的DDX/DDV ...