一道蓝桥杯题对于处理输入的启发

来源:互联网 发布:苏州php招聘 编辑:程序博客网 时间:2024/05/18 22:15
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;


int n,a[10000],i,len,j;
char s[100];


int main()
{
    cin >> n;
    gets(s);
    len = 0;
    int k = -1;
    for(i = 0; i<n; i++)
    {
        gets(s+1);
        s[0] = ' ';
        int flag = 0;
        for(j = 0; s[j]; j++)
        {
            if(s[j-1] == ' ' && s[j]!=' ')
            {
                k = s[j]-'0';
                flag = 1;
            }
            else if(s[j] == ' ')
            {
                if(k!=-1)
                    a[len++] = k;
                flag = 0;
                k = -1;
            }
            else if(flag)
                k = k*10+s[j]-'0';
        }
    }
    if(k!=-1)
    a[len++] = k;
    sort(a,a+len);
    int x = 0,y = 0;
    for(i = 1;i<=len;i++)
    {
        if(a[i] == a[i-1])
        y = a[i];
        else if(a[i]-a[i-1] == 2)
        x = a[i-1]+1;
    }
    cout << x << " " << y << endl;


    return 0;

}

找缺号和重号

样例输入1
2
5 6 8 11 9 
10 12 9
样例输出1
7 9
样例输入2
6
164 178 108 109 180 155 141 159 104 182 179 118 137 184 115 124 125 129 168 196
172 189 127 107 112 192 103 131 133 169 158 
128 102 110 148 139 157 140 195 197
185 152 135 106 123 173 122 136 174 191 145 116 151 143 175 120 161 134 162 190
149 138 142 146 199 126 165 156 153 193 144 166 170 121 171 132 101 194 187 188
113 130 176 154 177 120 117 150 114 183 186 181 100 163 160 167 147 198 111 119
样例输出2
105 120

0 0