• Finding


    题意:实验报告上有很多的数字,每个数字,出现偶数次,现在拿来三个数:x,y,z且有(x%4!=y%4)&&(y%4!=z%4)&&(x%4!=z%4)

    input

    第一行输入一个整数n,表示下面有n个整数

    接下来一行有n个整数

    output:

    输出三个数,(从小到大排列),俩俩数字之间用空格隔开

    Sample“

    11

    1 1 2 2 3 3 4 4 3 2 1

    ---------------------------------------------------------------------

    1 2 3

    第一种解法(Sort)

     1 #include<stdio.h>
     2 #include <algorithm>
     3 using namespace std;
     4 int main()
     5 {
     6 
     7     int n,i,m;
     8     while(~scanf("%d",&n))
     9     {
    10         int a[n];m=3;
    11         for(i=0;i<n;i++)
    12         {
    13             scanf("%d",&a[i]);
    14         }
    15         sort(a,a+n);
    16         for(i=0;i<n;i+=2)
    17         {
    18             if(a[i]!=a[i+1])
    19             {
    20                 if(m!=1)
    21                 printf("%d ",a[i]);
    22                 else
    23                   printf("%d
    ",a[i]);
    24                 m--;
    25                 i--;
    26             }
    27         }
    28     }
    29     return 0;
    30 }
    View Code

    第二个解法(map)没想到

     1 #include <map>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 using namespace std;
     5 
     6 int
     7 main(int argc, char *argv[])
     8 {
     9     int i;
    10     int n;
    11     int top;
    12     int number;
    13     int stack[3];
    14 
    15     while (EOF != scanf("%d", &n)) {
    16         map<int, int>mp;
    17         map<int, int>::iterator it;
    18 
    19         for (i=0; i<n; ++i) {
    20             scanf("%d", &number);
    21             ++mp[number];
    22         }
    23 
    24         top = 0;
    25 
    26         for (it = mp.begin(); it!=mp.end(); ++it) {
    27             if (0 != it->second%2) {
    28                 stack[top++] = it->first;
    29             }
    30         }
    31 
    32         if ((3 == top) && (stack[0]%4 != stack[1]%4)&&(stack[1]%4 != stack[2]%4)&&(stack[0]%4 != stack[2]%4)) {
    33             printf("%d %d %d
    ", stack[0], stack[1], stack[2]);
    34         }
    35 
    36         mp.clear();
    37     }
    38 
    39     exit(0);
    40 }
    View Code

  • 相关阅读:
    redis 布隆过滤器
    ltp分词加入词典后处理——强制分词
    python零散的小知识点
    icecream调试
    pandas操作excel的基础知识
    Neo4j在python中的基础操作
    正则表达式中的split的使用
    初始化方法__init__
    if语句中的多个条件**的并与交
    python爬虫
  • 原文地址:https://www.cnblogs.com/sxmcACM/p/3451653.html
Copyright © 2020-2023  润新知