第一范文网 - 专业文章范例文档资料分享平台

oj题

来源:用户分享 时间:2025/12/6 18:51:07 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

}

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 #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); }

搜索更多关于: oj题 的文档
oj题.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c2r2pv0mxwn0a0pl1tz0w_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top