Codeforces Beta Round #4 (Div. 2 only) C. Registration system

Source: Internet
Author: User

This problem feels good, before the dictionary tree written is the most comfortable, this several times the game hangs in the dictionary tree also has the shadow AH ~ ~



Main topic:

Give some strings, the query for each string, if there is no return OK, if there is a new string generated, the format of the original string + number, the number of occurrences of the string first several times.



Problem Solving Ideas:

A dictionary tree that counts the number of inserts for each string.



Here's the code:

#include <set> #include <map> #include <queue> #include <math.h> #include <vector># Include <string> #include <stdio.h> #include <string.h> #include <stdlib.h> #include < iostream> #include <cctype> #include <algorithm> #define EPS 1e-10#define pi acos ( -1.0) #define INF 107374182#define INF64 1152921504606846976#define LC l,m,tr<<1#define RC m + 1,r,tr<<1|1#define Zero (a) fabs (a) <eps#define iabs (x) ((x) > 0? (x):-(x)) #define CLEAR1 (A, X, SIZE) memset (A, X, sizeof (a[0]) * (min (size,sizeof (a))) #define ClearAll (A, X) memset (A, X , sizeof (a)) #define MEMCOPY1 (A, X, SIZE) memcpy (A, X, sizeof (X[0)) * (size)) #define Memcopyall (A, X) memcpy (A, X, sizeof ( x) #define MAX (x, Y) (((x) > (y))? (x): (y)) #define min (x, y) (((x) < (y))?    (x): (y)) using namespace std;struct node{int p; int num[26];} Node[500000];char s[50];int cnt,len;int insertstring (int strp,int p) {if (Strp==len) {node[p].p++;    return NODE[P].P;    } if (node[p].num[s[strp]-' a ']==0) {node[p].num[s[strp]-' a ']=cnt++; } return Insertstring (strp+1,node[p].num[s[strp]-' a ');}    int main () {int n,temp;    Cnt=1;    ClearAll (node,0);    scanf ("%d", &n);        for (int i=0;i<n;i++) {scanf ("%s", s);        Len=strlen (s);        Temp=insertstring (0,0);        if (temp==1) {puts ("OK");    } else printf ("%s%d\n", s,temp-1); } return 0;}


Codeforces Beta Round #4 (Div. 2 only) C. Registration system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.