1 solutions

  • 0
    @ 2025-11-5 14:59:57

    C :

    #include<stdio.h>
    #include<string.h>
    int a[100005];
    char ch[10000];
    int main()
    {
        //freopen("in.txt","r",stdin);
        int n, i, j, l, t, t1, t2, s, min, max;
        scanf("%d", &n);
        getchar();
        min = 100010; max = -1;
        memset(a, 0, sizeof(a));
        while(n--)
        {
            gets(ch);
            l = strlen(ch);
            s = 0;
            for(i = 0; i < l; i++)
            {
                s = 0;
                while(ch[i]>='0'&&ch[i]<='9')
                {
                    s *= 10;
                    s += (ch[i]-'0');
                    i++;
                }
                if(s>0)
                {
                    if(s > max) max = s;
                    if(s < min) min = s;
                    a[s]++;
                }
            }
        }
        for(i = min; i <= max; i++)
        {
            if(a[i] == 2)
                t2 = i;
            else if(a[i] == 0)
                t1 = i;
        }
        printf("%d %d", t1, t2);
    
        return 0;
    }
    
    

    C++ :

    #include<cstdio>
    int a[100003];
    int main()
    {
        //freopen("1.txt", "r", stdin);
        int i, n, s = 0, t = 0, l = 0, min = 1000000;
        int duan, chong;
        scanf("%d", &n);
        while(~scanf("%d", &n))
        {
            if(n < min)min = n;
            a[n]++;
            l++;
        }
        for(i=0; i<l; i++){
            if(a[min+i] == 0)duan = min+i;
            if(a[min+i] == 2)chong = min+i;
        }
        printf("%d %d\n",duan, chong);
        return 0;
    }
    
    

    Java :

    import java.util.Scanner;
     
    public class Main {
    	public static void main(String[] args) {
    		Scanner reader = new Scanner(System.in);
    		int N = reader.nextInt();
    		int[] array = new int[200];
    		int max = Integer.MIN_VALUE;
    		int min = Integer.MAX_VALUE;
    		for (int i = 0; i < array.length; i++) {
    			array[i] = Integer.MIN_VALUE;
    		}
    		int step = 0;
    		int s=0;
    		String str="";
    		while(s< N+1)
    		{
    				str= reader.nextLine();
    				String[] numStr = str.split(" ");
    				for (int i = 0; i < numStr.length; i++) {
    					if (numStr[i].equals("")) {
    						continue;
    					}
    					array[step] = Integer.parseInt(numStr[i]);
    					if (max < array[step])
    						max = array[step];
    					if (min > array[step])
    						min = array[step];
    					step=step+1;
    				}
    			s++;
    			
    		}
    			
    		int[] exist = new int[max + 1];
    		for (int i = 0; i < step; i++) {
    			if (exist[array[i]] == 0)
    				exist[array[i]] = 1;
    			else
    				exist[array[i]] = 2;
     
    		}
    		int repetion = 0;
    		int deletion = 0;
    		for (int i = min; i < max + 1; i++) {
    			if (exist[i] == 0)
    				deletion = i;
    			else if (exist[i] == 2)
    				repetion = i;
    		}
    		
    		System.out.println(deletion + " " + repetion);
    	}
     
    }
    
    • 1

    Information

    ID
    16307
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By