Fork me on GitHub

坑!一个空格引发的血案

今天在计蒜客上刷题,碰到一个巨坑的题(好吧,其实是自己粗心…)

题目链接:在这

题目

ACM-ICPC 2017 Asia Nanning 【A. Abiyoyo】

“Abiyoyo, Abiyoyo.”

“Abiyoyo, Abiyoyo.”

“Abiyoyo, yo yoyo yo yoyo.”

Once upon a time there was a little boy, who played a ukulele. He’d go around town: clink, clunk, CLONK! 

Of course, the grownups would be busy, and they would say: “Take that thing out of here. We are talking. Git!”

And they would kick him out of the house.

Now, in this town they used to tell stories. 

The old people used to tell stories about the monsters and giants that lived in the old days! 

They used to tell a story about Abiyoyo.

They said he was as tall as a house, and could eat people up. Of course, nobody believed it, but they told the stories anyway.

But one day, the sun rose, blood red over the hill, and the first people that got up and looked out of their window. 

They saw a great big shadow in front of the sun, and they could feel the whole ground shake.

Women screamed. Strong men fainted.

They said: “Run for your lives! Abiyoyo’s coming!” Down through the fields he came. 

He came to the sheep, pasture and grabs a whole sheep. Yeowp! He eats it down in one bite. He comes to the cow pasture. Yuhk!

Just then the boy woke up. The boy rubbed his eyes and said: “Hey, what is coming over the fields? Oh, it is Abiyoyo.”

He grabbed his ukulele. Over the fields he went, right up to where Abiyoyo was. People screamed “Don’t go near him! He will eat you alive!”

There was Abiyoyo. He had long fingernails because he never cut them. He had slobbery teeth because he never brushed them. 

Matted hair because he never combed it. Stinking feet because he never washed them. 

He was just about to come down with his claws, when the boy whipped out his ukulele.

Abiyoyo, Abiyoyo Abiyoyo, Abiyoyo Abiyoyo, yo yoyo yo yoyo Abiyoyo, yo yoyo yo yoyo.

Well, the monster had never heard a song about himself before, and a foolish grin spread across his face. And started to dance.

Abiyoyo, Abiyoyo.Abiyoyo,Abiyoyo.

The boy went faster.

Abiyoyo, yo yoyo, yo yoyo Abiyoyo, yoyo yoyo, ho ho ho ho ho ho ho ho.Abiyoyo,yoyoyo,yoyoyoAbiyoyo,yoyoyoyo,hohohohohohohoho.

The giant got out of breath. He staggered. He fell down flat on the ground.

“Booooom!” A hunter fired, and the Abiyoyo died. People streamed out of their houses, and ran across the fields.

They sang many times:

Abiyoyo, Abiyoyo.Abiyoyo,Abiyoyo.

Then they all sang:

Abiyoyo, yo yoyo yo yoyo.Abiyoyo,yoyoyoyoyoyo.

Abiyoyo, yo yoyo yo yoyo.Abiyoyo,yoyoyoyoyoyo.

Input
This problem has several test cases. The first line of the input contains an integer tt 

(1 \le t \le 20)(1≤t≤20) which is the number of test cases.

Then tt cases follow. For each test, a line contains an 

integer k (1 \le k \le 20)k(1≤k≤20) which means that people sang k times:

Abiyoyo, Abiyoyo.Abiyoyo,Abiyoyo.

Output
For each case, output all what they sang after the death of Abiyoyo in several lines.

样例输入
3
2
5
1
样例输出
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, Abiyoyo.
Abiyoyo, yo yoyo yo yoyo.
Abiyoyo, yo yoyo yo yoyo.

AC代码

#include<bits/stdc++.h>
int main()
{
    int t,k;
    scanf("%d",&t);
    if(t >= 1 && t <= 20)
    {
        while(t--)
        {
            scanf("%d",&k);
            if(k >= 1 && k <= 20)
            {
                for(int i = 0;i<k;i++)
                {
                    //if(i == k)printf("Abiyoyo, Abiyoyo.");
                    /*else*/ printf("Abiyoyo, Abiyoyo.\n");
                }
                for(int j = 0;j<2;j++)
                {
                    //if(j == 2) printf("Abiyoyo, yo yoyo yo yoyo.");
                    /*else*/ printf("Abiyoyo, yo yoyo yo yoyo.\n");
                }
            }
        }
    }
}

你以为你以为的就是你以为的?

一开始我以为是换行的问题,没想到是这个Abiyoyo, yo yoyo yo yoyo.中,Abiyoyo,后面还有一个空格…

所以正确输出是这样的:Abiyoyo + , + 空格 + yo + 空格 + yoyo + 空格 + yo + 空格 + yoyo

努力微笑.jpg

总结

  1. 一定要注意看题目的inputoutput格式!!!
  2. 不要急于submit…因为会上瘾的…而且会有罚时!!!
Adhere to original technology sharing, your support will encourage me to continue to create!