POJ 2001 Phone

Source: Internet
Author: User

#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <    string>using namespace Std;const int M = 26;int n; #define MAXN 1005char s[maxn][21];struct node{int v; Node *next[m];}    *root;void creat (char *s)//allocating memory is best used calloc because it initializes and malloc uninitialized is random data garbage {int len = strlen (s);    Node *p = root, *q;        for (int i=0; i<len; i++) {int id = s[i]-' a ';        cout<<id<< "";            if (p->next[id] = = NULL) {q = (node *) calloc (1, sizeof (node));            Q->v = 1;            P->next[id] = q;        p = q;            } else {p = p->next[id];        p->v++;    }}}void Find (char *s) {int len = strlen (s);    Node *p = root;        for (int i=0; i<len; i++) {int id = s[i]-' a ';        p = p->next[id];        printf ("%c", S[i]);    if (p->v = = 1) break; } Cout<<endl;}    int main () {n = 0; RooT = (node *) calloc (1, sizeof (node));    Root node//root = new node;    while (~SCANF ("%s", S[n]) {creat (s[n++]);        } for (int i=0; i<n; i++) {printf ("%s", S[i]);    Find (S[i]); } return 0;}

POJ 2001 Phone

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.