zoukankan      html  css  js  c++  java
  • ZOJ 3492 模拟循环链表线性查找

    WA了好几次最后找到错因是因为数组开小了! = =

    string whose length never exceeds 20

    所以至少要开到21 = = ,我却一直开20 ╮(╯▽╰)╭

    AC代码:

     1 #include <stdio.h>
     2 #include <string.h>
     3 int main(){
     4     int t,n,i,j,flag;
     5     char target[21],name[110][21];
     6     scanf("%d",&t);
     7     while(t--){
     8         scanf("%d%s",&n,target);
     9         for(i=0;i<n;i++)
    10             scanf("%s",name[i]);
    11         for(i=0;i<n;i++)
    12             if(strcmp(name[i],target) == 0) break;
    13         flag = (i + n/2)%n;
    14         printf("%s
    ",name[flag]);
    15     }
    16     return 0;
    17 }
    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
  • 相关阅读:
    inline关键字的作用
    Qt编写websocketpp客户端
    QThreadPool线程池的开发使用
    QThreadPool线程池的使用,线程与Widget通过信号与槽的方式通信。
    1、QThreadPool线程池的使用,线程和Widget通过QMetaObject::invokeMethod交互。
    QtTest模块出现控制台的原因与方案
    定长字符数组与不定长字符数组的初始化
    C#开发中localhost与127.0.0.1本地服务器的区别
    C#树目录(treeView)的编写
    SQLite的导入导出
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/3646344.html
Copyright © 2011-2022 走看看