poj1598

#include<iostream>
#include<fstream>
using namespace std;
int k,e,num[20],index,temp,m,times;
char keys[20][25],excuses[20][100],*str;
bool checkAlp(char x){
	if(x<'A'||x>'z'||(x>'Z'&&x<'a'))
		return false;
	return true;
}
int main(){
	//streambuf *backup; 
 //   ifstream fin; 
 //   fin.open("data.in"); 
 //   backup = cin.rdbuf();   // back up cin's streambuf 
 //   cin.rdbuf(fin.rdbuf()); // assign file's streambuf to cin 
	times=1;
	while(!cin.eof()){
		cin>>k>>e;
		memset(keys,0,sizeof(keys));
		memset(excuses,0,sizeof(excuses));
		memset(num,0,sizeof(num));		
		for(int i=0;i<k;i++){
			cin>>keys[i];
		}
		cin.get();
		for(int i=0;i<e;i++){			
			
			cin.getline(excuses[i],100);
		}
		for(int i=0;i<e;i++){
			index=0;			
			str=excuses[i];
			while(str[index]!=0){
				while(str[index]!=0&&!checkAlp(str[index]))
					index++;
				if(str[index]==0)
					break;
				for(int j=0;j<k;j++){					
					m=0;
					temp=index;
					while(keys[j][m]!=0){						
						if((!checkAlp(str[temp]))||((keys[j][m]!=str[temp])&&((keys[j][m]-'a'+'A')!=str[temp])))
							break;
						m++;
						temp++;
					}
					if(keys[j][m]==0&&(!checkAlp(str[temp]))){
						num[i]++;						
						break;
					}
				}
				while(checkAlp(str[index]))
					index++;
			}
		}
		int max=0;
		for(int i=0;i<e;i++)
			if(num[i]>max)
				max=num[i];
		
		cout<<"Excuse Set #"<<times<<endl;
		for(int i=0;i<e;i++){
			if(num[i]==max)
				cout<<excuses[i]<<endl;
		}
		cout<<endl;
		times++;				
	}
	//system("pause");
	return 0;
}

有几个函数可供参考

strcpy,isalpha,strlen,strcmp,sscanf(从字符串取格式数据)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值