The Number Off of FFF

X 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 1 to X , one by one, from left to right.

Now we have a continuous part from the original line.
There are N soldiers in the part.
So in another word, we have the soldiers whose id are between A and A+N−1 (1≤A≤A+N−1≤X ).
However, we don't know the exactly value of A , but we are sure the soldiers stands continuously in the original line, from left to right.

We are sure among those N soldiers, exactly one soldier has made a mistake.
Your task is to find that soldier.

Input

The first line has a number T (T≤10 ) , indicating the number of test cases.

For each test case there are two lines. First line has the number N ,
and the second line has N numbers, as described above. (3≤N≤105 )

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

Output

For test case X , output in the form of Case #X: L, L here means the position of soldier among the N soldiers
counted from left to right based on 1 .

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;
}

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

 

 

posted @ 2016-08-25 20:05  小小姐  阅读(217)  评论(0编辑  收藏  举报