Algorithm--antonyms of synonyms

Source: Internet
Author: User

Today to participate in the ACM school election, is really sad to despair, this year has not been compiled C + +, grammar are almost forgotten, get a hellowordl! For 20 minutes, it was a dog. The passing of the array forget clean (oneself too dish, game do not know why live call function time cannot pass an array) error, take Java code is accustomed to, change to C 艹 various 艹 ah. So I gave up halfway in the exam. Look at the side of the great God along the way to finish, own Ah, only do 2, school election have to pass!!!!! Watching the topic will do, will not use C + + on the paper to write Java code, the heart of this bitter. So to get C + + code, in C + +, in C + +.

Of course, today I still take Java to see this game a pretty interesting problem to realize it.

The topic is probably the meaning
* Synonyms antonyms, the rule of a word of the synonyms synonyms are also synonyms, the antonym of a word antonym for synonyms. , first enter two digits n t,n to represent n words, t for the following will have T row data
* There are three full rows of data a1,b1,c1 per line. A1 represents the A1 Word, B1 represents the first B1 word, C1 has two values of 0 and 1
* 0: two synonyms
* 1: Two for antonyms
* Determine if the T-line data is logical, if it is logical then return 0, if it does not conform to the line number that the error returned starts

This problem actually think the idea is not difficult, the idea of disintegration is that every word has a father, and a bunch of antonyms.

Each time a row of data is read, there are two cases c1=0 or c1=1

1. c1=0; If(A1 's father's Antonym library has B1 's father | | B1 's father's Antonym library has A1 's father)

return FALSE.


Add B1 's father's translator to A1 's father's antonym library

Let B1 's dad change to A1 's dad.

Let all father is B1 father's words (including B1) All change to recognize A1 father for father

return true;

2. c2=0

if (A1 's father's Thesaurus has B1 's father | | B1 's father's Thesaurus has A1 's dad)

return False


Let B1 's father's antonyms in the library add A1 's dad

Same A1 Dad's antonyms Library add B1 's dad

return true;

Okay, the main function is finished, we look at the code of the put hahaha

1 ImportJava.util.Scanner;2  Public classSynonymopposite {3     Static int[][]map;4     Static intwordfather[];5     StaticStringBuffer wordopposite[];6     Static intN;7      Public Static BooleanInitintA1,intB1,intC1) {8         if(c1==0)//Jinyici9         {Ten             if(Wordopposite[wordfather[a1]].indexof (string.valueof (WORDFATHER[B1))!=-1| | Wordopposite[wordfather[b1]].indexof (string.valueof (WORDFATHER[A1))!=-1) One                 return false; A             Else -             { -                  intB1father =WORDFATHER[B1]; the                   for(inti=1;i<=n;i++) -                  { -                      if(Wordfather[i]==b1father)//link it to the A1 . -                      { +wordfather[i]=WORDFATHER[A1]; -                      } +                  } AWordopposite[a1].append (Wordopposite[wordfather[b1]].tostring ());//Synchronous antonyms at             } -         } -         Else -         { -             if(wordfather[a1]==WORDFATHER[B1]) -             { in                 return false; -             } to             Else +             { - wordopposite[wordfather[a1]].append (wordfather[b1]); the wordopposite[wordfather[b1]].append (wordfather[a1]); *             } $         }Panax Notoginseng         return true; -     } the      Public Static voidMain (string[] args) { +         //TODO auto-generated Method Stub A        intCol=0; theScanner sc=NewScanner (; +n=sc.nextint (); -map=New int[N+1] [N+1]; $Wordfather=New int[N+1]; $Wordopposite=NewStringBuffer [n+1]; -         for(inti=1;i<=n;i++) -        { thewordfather[i]=i;  -wordopposite[i]=NewStringBuffer ();Wuyi        }   theCol=sc.nextint (); -         int[]a1=New int[Col+1]; Wu         int[]b1=New int[Col+1]; -         int[]c1=New int[col+14]; About         for(inti=1;i<=col;i++) $        { -a1[i]=sc.nextint (); -b1[i]=sc.nextint (); -c1[i]=Sc.nextint ();  A        } +        intI=0; the         for(i=1;i<=col;i++) -        { $            if(!Init (A1[i], b1[i], c1[i])) the            { the System.out.println (i); theI=0; the                 Break; -            } in        } the       if(i!=0) theSYSTEM.OUT.PRINTLN ("Yes");  About           the     } the  the}

Algorithm--antonyms of synonyms

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: 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.