The Number Off of FFF

时间:2023-03-09 08:40:51
The Number Off of FFF

The Number Off of FFFX soldiers from the famous “FFF army'' is standing in a line, from left to right.

You, as the captain of FFF, decides to have a number off, that is, each soldier,
from left to right, calls out a number.
The first soldier should call One, each other soldier should call the number next to the number
called out by the soldier on his left side. If every soldier has done it right,
they will call out the numbers from The Number Off of FFF1

to The Number Off of FFFX

, one by one, from left to right.

Now we have a continuous part from the original line.
There are The Number Off of FFFN

soldiers in the part.
So in another word, we have the soldiers whose id are between The Number Off of FFFA

and The Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFA+N−1

(The Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFF1≤A≤A+N−1≤X

).
However, we don't know the exactly value of The Number Off of FFFA

, but we are sure the soldiers stands continuously in the original line, from left to right.

We are sure among those The Number Off of FFFN

soldiers, exactly one soldier has made a mistake.
Your task is to find that soldier.

Input

The first line has a number The Number Off of FFFT (The Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFT≤10 ) , indicating the number of test cases.

For each test case there are two lines. First line has the number The Number Off of FFFN ,
and the second line has The Number Off of FFFN

numbers, as described above. (The Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFFThe Number Off of FFF3≤N≤105

)

It guaranteed that there is exactly one soldier who has made the mistake.

Output

For test case The Number Off of FFFX

, output in the form of Case #X: L, The Number Off of FFFL

here means the position of soldier among the The Number Off of FFFN

soldiers
counted from left to right based on The Number Off of FFF1

.

Sample Input

2
3
1 2 4
3
1001 1002 1004

Sample Output

Case #1: 3
Case #2: 3

这个题很好理解,就是一个序列,每个数比前一个数大一,如果不是就是错误的,要求输出错误的数

但是我有一个疑问,如果后面的都对,就第一个不对怎么办?

我跟同学商量了一下,但是他说不可能,是一遍输入一遍判断,一开始我以为我读错了,但是现在发现不是那回事好像,因为一开始要求输入几个数,然后再输入各个数,如果1 2 4 5该怎么办,这个算哪个错,然后我就不管不顾的写了代码,对了

#include<cstdio>
int main()
{
    int t,n,x,j,i,y;
    scanf("%d",&t);
    for(i=1;i<=t;i++)
    {
        scanf("%d",&n);
        scanf("%d",&x);
        int cnt=1;
        for(j=2;j<=n;j++)
        {
            scanf("%d",&y);
            if(y-x!=1)
            {
                cnt=j;
            }
            x=y;
        }
        printf("Case #%d: %d\n",i,cnt);
    }
    return 0;
}

同学写的就是考虑了我举得例子,他是按第一个是正确答案输出的

#include<stdio.h>
int main()
{
    int T,N,i,j,k,temp,cnt,flag;
    scanf("%d",&T);
    for(i=1;i<=T;i++)
    {
        scanf("%d",&N);
        scanf("%d",&temp);
        flag=cnt=1;
        for(j=2;j<=N;j++)
        {
            scanf("%d",&k);
            if(k-temp!=1&&flag)
                {cnt=j;flag=0;}
            temp=k;
        }
        printf("Case #%d: %d\n",i,cnt);
    }
    return 0;
}

这个应该很好理解吧,水题啊