1. 程式人生 > >第四屆藍橋杯第七題 錯誤票據

第四屆藍橋杯第七題 錯誤票據

.com n) Go col nbsp lag int com while

技術分享圖片

題解:寫了簡單題,好開心,我果然不適合學算法.......寫寫簡單題,當個鹹魚就好了嘛!!

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <sstream>
using namespace std;

const int maxn = 100000 + 50;
int N;
int num[maxn];

void solve()
{
    
int cnt = 0; string line; int a; getchar(); for (int i = 0; i < N; i++) { getline(cin, line); istringstream in(line); while (in >> a) { num[cnt++] = a; } } sort(num, num + cnt); int m = 0, n = 0;
int flag_m = 0, flag_n = 0; for (int i = 0; i < cnt - 1; i++) { if (num[i + 1] - num[i] > 1 && !flag_m) { m = num[i] + 1; flag_m = 1; } if ((num[i] == num[i + 1]) && !flag_n) { n = num[i]; flag_n
= 1; } if (flag_m && flag_n) { break; } } printf("%d %d\n", m, n); } int main() { cin >> N; solve(); return 0; }

第四屆藍橋杯第七題 錯誤票據