水题 HDOJ 4727 The Number Off of FFF

 

题目传送门

 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 */

 

你可能感兴趣的:(number)