Description
In the English literature, especially in the professional literature, there are often many abbreviations, such as CPU on behalf of Central processing Unit and so on. To facilitate learning, Qili decided to extract all the acronyms and their full names from a group of English papers.
Initially, the abbreviations for these articles appear in all uppercase letters, and each abbreviation has a space after it, followed by its full name. The full name is enclosed in "()", there is no space between the left parenthesis and the word behind it, there is no space between the right parenthesis and the word in front of it, and the first letter of each word of the full name corresponds to the order of the abbreviations. There may be a hyphen "-" connection between the full name of the word.
You help Qili write this program and extract all the acronyms and names.
Input
An English article in which each abbreviation appears for the first time, followed by its full English name, and the same abbreviation will no longer appear when it appears again. Each abbreviation and full name is not too long. The total number of acronyms is less than 100.
Output
If there is an abbreviation, the first line outputs "abbreviation ==> full Name". Each abbreviation and its full name are followed by a line, including the abbreviation number (starting at 1), the abbreviation, the delimiter (==>), and the full name. All outputs are divided into two parts (==>), the right side is left-aligned, the left-hand abbreviation is right-aligned, but the ordinal and the first line of "abbreviation" are left-aligned. Each abbreviation is output only once.
If there is no acronym, the output: There is no abbreviations in the this text.
Sample InputCOMputers such as the ENIAC (Electronic Numerical Integrator and computer) had to BES physically rewired in order to PE Rform different tasks, which caused these machines to be called "Fixed-program computers."Sample Outputabbreviation ==> full Name 1:eniac ==> Electronic Numerical Integrator and computerHINT
Note: Uppercase is not always abbreviated, and the parentheses are not necessarily full names. You can do a function that ignores the case of letters with the same character.
when extracting abbreviations, it should be noted that English words are not necessarily separated by spaces, some English words are with hyphens, but the initials are also extracted.
The problem needs to be considered more, but the choice of thinking is different, the complexity of the problem may be different. In addition, in the reading, I also exist a lot of mistakes, due to the problem of reading problems, leading to the idea of choice is not appropriate, so that the last change in the code of the more chaotic. I summed up the need to pay attention to the following points: 1. Be sure to do the problem before serious analysis of the topic, word-for-word reading, want to know how to write code, so that can play a multiplier effect 2. Write-side tests, and make sure that the previous code is completely correct before you continue writing the program. 3. Pay attention to the use of functions, the proper use of functions can be more clear program structure 4. Consider all extreme situations, such as the beginning, the end, no solution, one solution, one letter, etc., especially when using pointers to cross-border access
Here is a sticker for my code:
1#include <stdio.h>2#include <ctype.h>3#include <string.h>4 Charstr[1000000];5 voidPrintste (Char*s,Char*e) {6 while(s<=e) Putchar (*s++);7 }8 intIs_upper (Char*s,Char*e) {9 while(s<=e)if(!isupper (*s++))return 0;Ten return 1; One } A intMatch_word (Char*s,Char*e,Char* as,Char*AE) { - if(s>e| | as>ae| | * (e) = =' ')return 0; - while(s<=e&& as<=AE) { the if(* as++!=toupper (*s++))return 0; - while(*s!=' '&&*s!='-') s++; -s++; - } + if(s<=e)return 0; - return 1; + } A voidSearchChar*p) { at intCnt=0; - Char* p0=p,*P1; - while(p0!=NULL) { - intok=1; - Char*P3;//P0 representative (, P1 representative), P3 for acronym initials - if(P0=STRCHR (P0,'(')) ==null) Break; in if((P1=STRCHR (p0+1,')')) ==null) Break; -p3=p0-2; to if(p3-p>=0&&* (p3+1)==' ') while(p3-p>=0&&isupper (* (p3))) p3--;//prevent subscript from crossing + Elseok=0; - if(Islower (* (p3))) ok=0; the if(Ok&&match_word (p0+1, p1-1, ++p3,p0-2)){ * if(!cnt) printf ("abbreviation ==> full name\n"); $printf"%d:",++CNT);Panax Notoginseng* (p0-1)=' /'; - if(CNT)/Ten==0) printf ("%10s", p3); the Else if(CNT)/ -==0) printf ("%9s", p3); +* (p0-1)=' '; Aprintf"==>"); thePrintste (p0+1, p1-1); +printf"\ n"); - } $p0=P1; $ } - if(cnt==0) printf ("There is no abbreviations in this text.\n"); - } the intMain () { - intch;Wuyi intk=0; the while((Ch=getchar ())! =EOF) -Str[k++]= (ch=='\ n')?' ': ch; Wustr[k]=' '; str[k++]=' '; str[k++]=0;//Prevent subscript from being crossed at the end of a string - search (str); About return 0; $}
Sdust operation problem J: extracting abbreviations