}
}
printf(\
return 0; }
int change(char str1[]) { int i,j;
char str2[10001];
for (i = 0,j = 0;str1[i] != '\\0' ;i++ ) {
if (str1[i] >= 'A' && str1[i] <= 'Z') {
str2[j++] = str1[i];
}
else if (str1[i] >= 'a' && str1[i] <= 'z') {
str2[j++] = str1[i] - 32;
} }
str2[j] = '\\0'; strcpy(str1,str2); }
void secret(char str[],int k) {
int i,count = 0;
for (i = 0;str[i] != '\\0';i += 1) {
str[i] = str[i] + k; if (str[i] > 'Z')
} }
{ }
else if (str[i] < 'A') { }
str[i] += 26; str[i] -= 26;
Problem E: 提取缩略词
Description
在英文文献中,尤其是专业文献中,经常有很多的缩略词,如CPU代表Central Processing Unit等。为了方便学习,Qili决定从一批英文论文中提取出所有的缩略词以及它们的全称。 经过初步判断,这些文章的缩略词都是以全部大写字母的形式出现,而且每个缩略词之后会有一个空格,之后是它的全称。全称使用“()”括起来,左括号跟它后面的单词之间没有空格,右括号跟它前面的单词之间没有空格,全称的每个单词的首字母与缩略词的顺序是对应的。全称的单词之间可能有连字符“-”连接。
你来帮Qili编写这个程序,将所有的缩略词和全称提取出来。
Input
一篇英文文章,每个缩略词第一次出现时,其后都跟有它的英文全称;同样的缩略词再出现时,将不再出现全称。每个缩略词和全称都不会太长。缩略词总数小于100。
Output
如果有缩略词,第一行输出“Abbreviation ==> Full Name”。之后每个缩略词和它的全称占一行,包括缩略词的序号(从1开始)、缩略词、分隔符(==>)和全称。所有输出以分隔符(==>)分为两部分,右侧的全称左对齐,左侧的缩略词右对齐,但序号和第一行的“Abbreviation”是左对齐的。每个缩略词只输出一遍。
如果没有缩略词,则输出:There is no abbreviations in this text.
Sample Input
COMputers such as the ENIAC (Electronic Numerical Integrator And Computer) had to be
physically rewired in order to perform different tasks, which caused these machines to be called \
Sample Output
Abbreviation ==> Full Name 1: ENIAC ==> Electronic Numerical Integrator And Computer
HINT
注意:大写的不一定都是缩写,有括号的不一定都是全称。可以做一个函数忽略字母的大小写判断字符相同。
Append Code
#include
int isUpperChar(char ch);
int main(int argc,char* argm[]) {
char ch; char abbr[11],fullname[101]; int i = 0,j = 0,flag = 0,count = 0; while ((ch = getchar()) != EOF) { if(flag == 1 && (ch > 'Z' || ch < 'A') && ch != ' ') { flag = 0; i = 0; } if (flag == 2 && ch != '(') { flag = 0; i = 0; } if (flag == 0 && isUpperChar(ch)) { abbr[i++] = ch; flag = 1; } else if (flag == 1 && isUpperChar(ch)) { abbr[i++] = ch; } else if (flag == 1 && ch == ' ') {
abbr[i] = '\\0'; flag = 2; } if(flag == 2 && ch == '(') { flag = 3; } else if (flag == 3 && ch != ')') { fullname[j++] = ch; } else if (flag == 3 && ch == ')') { fullname[j] = '\\0'; flag = 0; i = 0; j = 0; count++; if (count == 1) { printf(\ } if (count >= 1 && count < 10) { printf(\ } else if(count >= 10) {
printf(\ } } } if(count == 0) {
printf(\ } return 0; }
int isUpperChar(char ch) {
return((ch >= 'A' && ch <= 'Z')?1:0); }
相关推荐: