苏州大学2008年复试上机真题

题目描述:

文件中按文本方式存放了一段其他文章,其中有若干长度小于15的英文单词,单词之间用空格分开,无其他符号。顺序读取这段文章的不同的单词(大小写敏感),同时在读取的过程中排除所有的单词THE以及变形,即这些单词不能出现在读取的结果中。将读取的所有单词的首字母转大写后,输出到文件中,每个单词一行。

输入描述:

The constructor is used to initialize the object The destructor is used to delete the Object the calling sequence of constructor is opposite to the calling sequence of destructor

输出描述:

Constructor
Is
Used
To
Initialize
Object
Destructor
Delete
Object
Calling
Sequence
Of
Opposite

代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	char word[100][15];
	char store[15];
	FILE *fp,*fa;
	int i=0,j=0,s=0;
	int res=-1;
	if((fp=fopen("D:\\2019Post\\pat\\pat\\data2008.txt","r"))==NULL){
		printf("can not open the file");
		exit(0);
	}
	while(!feof(fp)){
		fscanf(fp,"%s",word[i]);
		i++;
	}
	
	if((fa=fopen("D:\\2019Post\\pat\\pat\\data2008_out.txt","w"))==NULL){
		printf("can not open the file");
		exit(0);
	}
	for(j=0;j<i;j++){
		strcpy(store,word[j]);//很重要,不然的话会改掉data中的数据,以至于结果中出现重复。
		if(strcmp("The",store)!=0&&strcmp("the",store)!=0){
			res=1;
			for(s=0;s<j;s++){
				if(strcmp(word[s],store)==0)
					res=0;
			}

		}
		if(res==1){
			if(store[0]>='a'&&store[0]<='z'){
				store[0]-=32;
			}
			
			fprintf(fa,"%s\n",store);
			res=-1;
		}
		

	}
	fclose(fp);
	fclose(fa);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值