hdu The Number Off of FFF



链接:http://acm.hdu.edu.cn/showproblem.php?pid=4727


题目大意:在队伍中找出1个报数报错的人的序号。

算是很容易的题。

要注意的:因为这个队伍本来是从其他队伍拉出来的,所以可能这个队伍的第一个人就错了而后面的都对


没有考虑到第一个是错的情况,所以一开始就错了。how foolish i am....


#include<iostream>
using namespace std;
int a[100005];
int main()
{
    int T,n;
    scanf("%d",&T);
    int time=1;
    while(T--)
    {
        scanf("%d",&n);
        int temp=1,b;
        temp=1;
        for(b=1;b<=n;b++)
        {
            scanf("%d",&a[b]);
        }
        for(b=2;b<=n;b++)
        {
            if(a[b]==a[b-1]+1)
                temp=b;
            else
                break;
        }
        if(b==n+1)//if b==n+1 ,means the first one is false
            temp=0;
        printf("Case #%d: %d\n",time++,temp+1);
    }
    return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值