zoukankan      html  css  js  c++  java
  • AOJ.559 丢失的数字

    丢失的数字

    Time Limit: 1000 ms Memory Limit: 64 MB
    Total Submission: 1552 Submission Accepted: 273
    Description
    有N个数字是来自一个长度为N+1的连续整数序列,但是给你的并不是有序的,请你帮忙找出来是缺失的那个数字是在序列的两边还是中间

    Input

    有多组测试数据,每组测试数据包括2行,第一行包括一个整数N(0

    Output

    每组测试数据输出结果:
    中间缺失输出M,两边缺失输出S

    Sample Input

    5
    2 3 7 5 6
    5
    3 4 2 5 6
    0

    Sample Output

    Case 1:
    M
    Case 2:
    S

    题意分析

    给出一串数字,排序,如果下一个元素不等于上一个元素+1,输出M。否则输出S。

    代码总览

    /*
        Title:AOJ.559
        Author:pengwill
        Date:2016-11-14
    */
    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
    #include<algorithm>
    #define max 10005
    int a[max];
    using namespace std;
    int comp(const void *a, const void *b)
    {
        return *(int*)a - *(int*)b;
    }
    
    int main()
    {
        int n,t = 1,i;
        while(scanf("%d",&n) != EOF && n!= 0){
            for(i = 0;i<n;++i){
                scanf("%d",&a[i]);
            }
            int judge = 0;
            qsort(a,n,sizeof(a[0]),comp);
            for(i = 0;i<n-1;++i){
                if(a[i+1] != a[i]+1){
                    judge = 1;
                }
            }
            if(judge){
                printf("Case %d:
    M
    ",t);
            }else{
                printf("Case %d:
    S
    ",t);
            }
            t++;
        }
        return 0;
    }
  • 相关阅读:
    面试2
    面试总结
    谈谈扫码支付的实现流程
    从产品分类、模块功能和业务流程,了解支付产品服务的设计
    【提现】的业务流程
    APP测试点归纳
    安全测试的思路
    一 大型网站架构演化(大型网站技术架构原理)
    Tomcat服务器原理详解
    Tomcat目录结构详解
  • 原文地址:https://www.cnblogs.com/pengwill/p/7367252.html
Copyright © 2011-2022 走看看