Ultraviolet A 642-word Amalgamation

Source: Internet
Author: User

Question: Give You A Word List, give you new words, and re-arrange the words in the output list to get the new word.

Analysis: string. Sort the letters of each string to generate a new F (STR). Sort the entire string by binary.

Note: The output must satisfy the Lexicographic Order. Sort the output before searching.

#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;typedef struct wnode{char word[7];char abcd[7];}words;words W[101];int cmp(words a, words b){int c = strcmp(a.abcd, b.abcd);if (c != 0) return c<0;return strcmp(a.word, b.word)<0;}int bs(char str[], int r){int l = 0,m,c;while (l < r) {m = (l+r)/2;c = strcmp(W[m].abcd, str);if (c < 0) l = m+1;else r = m;}return l;}char buf[7];int main(){int count = 0;while (gets(W[count].word) && strcmp(W[count].word, "XXXXXX")) {strcpy(W[count].abcd, W[count].word);sort(W[count].abcd, W[count].abcd+strlen(W[count].abcd));count ++;}sort(W, W+count, cmp);while (gets(buf) && strcmp(buf, "XXXXXX")) {sort(buf, buf+strlen(buf));int s = bs(buf, count-1),flag = 0;while (!strcmp(buf, W[s].abcd)) {printf("%s\n",W[s ++].word);flag = 1;}if (!flag) printf("NOT A VALID WORD\n");printf("******\n");}return 0;}

Ultraviolet A 642-word Amalgamation

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.