2008--2009年北京航空航天大学计算机研究生机试真题
来源:互联网 发布:win7照相机软件下载 编辑:程序博客网 时间:2024/05/30 02:53
http://ac.jobdu.com/problem.php?pid=1165 字符串匹配
#include<iostream>#include<cstdio>#include<cstring>using namespace std;char str[1005][500],temp[1005][500],pattern[1005];inline bool pre_match(int j,int start,int end){int i;for(i=start;i<=end;i++){if(temp[j][i]!=pattern[i])return false;}return true;}inline bool middle_match(int j,int start,int end){int i;for(i=start+1;i<end;i++){if(temp[j][start]==pattern[i])return true;}return false;}inline bool post_match(int j,int start,int end){int i,p;for(i=start+1,p=end+1;temp[j][i]!='\0' && pattern[p]!='\0' ;i++,p++){if(temp[j][i]!=pattern[p])return false;}return true;}int main(void){int i,j,n,st,en;while(scanf("%d",&n)!=EOF){for(i=0;i<n;i++){scanf("%s",str[i]);strcpy(temp[i],str[i]);}for(i=0;i<n;i++){for(j=0;temp[i][j]!='\0';j++){if(temp[i][j]>='a') //将字符串中的字符全部转换为大写,数字则不变temp[i][j]-=32;}}scanf("%s",pattern);st=en=-1;for(i=0;pattern[i]!='\0';i++){if(pattern[i]>='a')pattern[i]-=32;if(pattern[i]=='[')st=i;else if(pattern[i]==']')en=i;}if(st==-1) //不存在中括号表示的模式匹配{for(i=0;i<n;i++){if(strcmp(temp[i],pattern)==0){printf("%d %s\n",i+1,str[i]);break;}}}else{for(i=0;i<n;i++){if(strlen(str[i]) != strlen(pattern) - (en - st) )continue;if(pre_match(i,0,st-1) && middle_match(i,st,en) && post_match(i,st,en)) //前缀、中间、后缀分别都匹配{printf("%d %s\n",i+1,str[i]);}}}}return 0;}
http://ac.jobdu.com/problem.php?pid=1168 字符串的查找删除
#include<iostream>#include<cstdio>using namespace std;#include<string.h>char str[1000][1000],s[1000];int slen;bool match(int j,int len,int index){int i,p;for(i=j,p=0;i<j+len && p<slen;i++,p++){if(s[p]!=str[index][i]){if(s[p]-str[index][i]!=32 && str[index][i]-s[p]!=32) //大小写不敏感return false;}}return true;}int main(void){int i,j,n=0,len;//freopen("a.txt","w",stdout);scanf("%s",s);slen=strlen(s);getchar();while(gets(str[n])){if(strcmp(str[n],"}")==0)break;n++;}for(i=0;i<=n;i++){len=strlen(str[i]);for(j=0;j<=len-slen;j++){if(str[i][j]==' ')continue;if(!match(j,slen,i)) //不匹配的话直接输出printf("%c",str[i][j]);else //匹配的话直接跳过,不输出j=j+slen-1;}for(;j<len;j++)printf("%c",str[i][j]);printf("\n");}return 0;}
- 2008--2009年北京航空航天大学计算机研究生机试真题
- 题目1163:素数 2008年北京航空航天大学计算机研究生机试真题
- 简单的素数问题(2008年北京航空航天大学计算机研究生机试真题)
- 九度机试 题目1165:字符串匹配 2008年北京航空航天大学计算机研究生机试真题
- 题目1163:素数(2008年北京航空航天大学计算机研究生机试真题)
- 2009年清华大学计算机研究生机试真题
- 2008年清华大学计算机研究生机试真题
- 2008年清华大学计算机研究生机试真题
- 2006年清华大学计算机研究生机试真题
- 2010年清华大学计算机研究生机试真题
- 2000年清华大学计算机研究生机试真题
- 2012年清华大学计算机研究生机试真题
- 2000年清华大学计算机研究生机试真题
- 2006年清华大学计算机研究生机试真题
- 2010年清华大学计算机研究生机试真题
- 2011年清华大学计算机研究生机试真题
- 2011年清华大学计算机研究生机试真题之四
- 2003年清华大学计算机研究生机试真题之五
- SDRAM之我见(转)
- 解析Spring IOC原理——工厂模式与反射机制的综合应用
- 来自数据源的string类型的给定值不能转换为指定目标列的类型nvarchar
- NSString+NSMutableString+NSValue+NSAraay用法汇总
- python核心编程学习(七)
- 2008--2009年北京航空航天大学计算机研究生机试真题
- poj3440
- 网站性能并发测试工具
- MVC日积月累 经典学习
- [MSSQL]SQL Server 2008 Using the MERGE statement
- JAVA学习——容器(概述)
- CGGeometry.h
- 正向代理与反向代理
- android 从任意activity退出程序