救救孩子吧,60 分调不出来啦
查看原帖
救救孩子吧,60 分调不出来啦
52381
CodingJellyfish楼主2021/10/14 16:21
#include <ctype.h>
#include <stdio.h>
#include <string.h>

// Consts

#define RN 50005
#define HASH 3233323

// Defs

typedef struct
{
    int nxt;
    int val;
    char tag;
}
HNode;

// IO

#define IO 10000
char _ibuf[IO]  , _obuf[IO];
char *_i = _ibuf, *_o = _obuf;

void initIO(void)
{
    fread(_ibuf, sizeof(char), IO, stdin);
}

void endIO(void)
{
    fwrite(_obuf, sizeof(char), _o - _obuf, stdout);
}

static inline char getch(void)
{
    if (_i == _ibuf + IO)
    {
        memset(_ibuf, 0, sizeof(_ibuf));
        fread(_ibuf, sizeof(char), IO, stdin);
        _i = _ibuf;
    }
    return *_i++;
}

static inline void putch(char ch)
{
    if (_o == _obuf + IO)
    {
        fwrite(_obuf, sizeof(char), IO, stdout);
        _o = _obuf;
    }
    *_o++ = ch;
}

int getint(void)
{
    int num = 0, fac = 1;
    char ch = getch();
    
    while (!isdigit(ch))
    {
        if (ch == '-')
            fac = -1;
        ch = getch();
    }
    while (isdigit(ch))
    {
        num = num * 10 + ch - '0';
        ch = getch();
    }
    return num * fac;
}

void putint(int val)
{
    if (val < 0)
    {
        val = -val;
        putch('-');
    }
    if (val >= 10)
        putint(val / 10);
    
    putch(val % 10 + '0');
}

// Main

HNode node[RN];
unsigned short head[HASH];

int main(void)
{
    initIO();
    int t = getint();
    while (t--)
    {
        int n = getint();
        for (int i = 1; i <= n; i++)
        {
            int v = getint(), h = head[(unsigned) v % HASH];
            if (!h)
            {
                node[i].val = v;
                head[(unsigned) v % HASH] = i;
            }
            else for (int j = h; j; j = node[j].nxt)
            {
                if (v == node[j].val)
                {
                    node[i].tag = 1;
                    break;
                }
                else if (!node[j].nxt)
                {
                    node[i].val = v;
                    node[j].nxt = i;
                    break;
                }
            }
        }
        for (int i = 1; i <= n; i++)
        {
            if (!node[i].tag)
                putint(node[i].val), putch(' ');
        }
        putch('\n');
        memset(head, 0, sizeof(head));
        memset(node, 0, sizeof(node));
    }
    endIO();
    return 0;
}
2021/10/14 16:21
加载中...