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;
    }
  • 相关阅读:
    ES6与ES5对比 模板字符串
    ES6 4个方法
    apicloud 聊天输入框模块UIChatBox
    apiCloud 调微信支付,调支付宝支付
    apiCloud 版本号
    apiCloud 下拉刷新
    apiCloud 上拉加载
    微信小程序页面内转发 按钮 转发
    CodeSmith datagridview属性
    CodeSmith listview属性
  • 原文地址:https://www.cnblogs.com/pengwill/p/7367252.html
Copyright © 2011-2022 走看看