码迷,mamicode.com
首页 > 其他好文 > 详细

水题 HDOJ 4727 The Number Off of FFF

时间:2015-04-19 21:02:14      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 1 /*
 2     水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错
 3 */
 4 #include <cstdio>
 5 #include <iostream>
 6 #include <algorithm>
 7 #include <cstring>
 8 #include <string>
 9 #include <cmath>
10 using namespace std;
11 
12 const int MAXN = 1e5 + 10;
13 const int INF = 0x3f3f3f3f;
14 int a[MAXN];
15 int b[MAXN];
16 
17 int main(void)        //HDOJ 4727 The Number Off of FFF
18 {
19     //freopen ("L.in", "r", stdin);
20 
21     int t, cas = 0;
22     int n;
23     scanf ("%d", &t);
24     while (t--)
25     {
26         scanf ("%d", &n);
27 
28         a[0] = b[0] = 0;
29         for (int i=1; i<=n; ++i)
30         {
31             scanf ("%d", &a[i]);
32             b[i] = a[i] - a[i-1];
33         }
34 
35         int ans = -1;
36         for (int i=2; i<=n; ++i)
37         {
38             if (b[i] != 1)
39             {
40                 ans = i;    break;
41             }
42         }
43         if (ans == -1)    ans = 1;
44 
45         printf ("Case #%d: %d\n", ++cas, ans);
46     }
47 
48     return 0;
49 }
50 
51 /*
52 Case #1: 3
53 Case #2: 3
54 */

 

水题 HDOJ 4727 The Number Off of FFF

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4439782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!