zoukankan      html  css  js  c++  java
  • CSP201412-1:门禁系统

    引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp是由中国计算机学会(CCF)发起的“计算机职业资格认证”考试,针对计算机软件开发、软件测试、信息管理等领域的专业人士进行能力认证。认证对象是从事或将要从事IT领域专业技术与技术管理人员,以及高校招考研究生的复试对象。

    问题描述

      涛涛最近要负责图书馆的管理工作,需要记录下每天读者的到访情况。每位读者有一个编号,每条记录用读者的编号来表示。给出读者的来访记录,请问每一条记录中的读者是第几次出现。

    输入格式

      输入的第一行包含一个整数n,表示涛涛的记录条数。

      第二行包含n个整数,依次表示涛涛的记录中每位读者的编号。

    输出格式

      输出一行,包含n个整数,由空格分隔,依次表示每条记录中的读者编号是第几次出现。

    样例输入

      5

      1 2 1 1 3

    样例输出

      1 1 2 3 1

    评测用例规模与约定

      1≤n≤1,000,读者的编号为不超过n的正整数。

    源代码

     1 # include <stdio.h>
     2 # include <stdlib.h>
     3 # include <memory.h>
     4 
     5 struct MyData {
     6     int key;
     7     int value;
     8 };
     9 
    10 int main(void)
    11 {
    12     int n;  //个数
    13     int flag = 1;
    14     int count = 0;
    15     scanf("%d", &n);
    16     
    17     int  *input = (int *)malloc(sizeof(int) * n);
    18     memset(input, 0, sizeof(int) * n);
    19     struct MyData *temp = (struct MyData *)malloc(sizeof(struct MyData) * n);
    20     memset(temp, 0, sizeof(struct MyData) * n);
    21     
    22     for (int i = 0; i < n; i++)
    23     {
    24         scanf("%d", input+i);        
    25     } 
    26     
    27     for (int i = 0; i < n; i++)
    28     {
    29         for (int j = 0; j < count; j++)
    30         {
    31             if (input[i] == temp[j].key)
    32             {
    33                 temp[j].value += 1;
    34                 count += 1;
    35                 flag = 0;
    36                 if (i == n-1)
    37                 {
    38                     printf("%d
    ", temp[j].value);
    39                 }
    40                 else
    41                 {
    42                     printf("%d ", temp[j].value);
    43                 }
    44                 break;
    45             }
    46         }
    47         if (flag)
    48         {
    49             temp[count].key = input[i];
    50             temp[count].value = 1;
    51             if (i == n-1)
    52             {
    53                 printf("%d
    ", temp[count].value);
    54             }
    55             else
    56             {
    57                 printf("%d ", temp[count].value);
    58             }
    59             count += 1;
    60         }
    61         flag = 1;
    62     }
    63     
    64     free(input);
    65     free(temp);
    66     
    67     return 0;
    68 } 
  • 相关阅读:
    POJ 2240 Arbitrage spfa 判正环
    POJ 3259 Wormholes spfa 判负环
    POJ1680 Currency Exchange SPFA判正环
    HDU5649 DZY Loves Sorting 线段树
    HDU 5648 DZY Loves Math 暴力打表
    HDU5647 DZY Loves Connecting 树形DP
    CDOJ 1071 秋实大哥下棋 线段树
    HDU5046 Airport dancing links 重复覆盖+二分
    HDU 3335 Divisibility dancing links 重复覆盖
    FZU1686 神龙的难题 dancing links 重复覆盖
  • 原文地址:https://www.cnblogs.com/husterzxh/p/8410831.html
Copyright © 2011-2022 走看看