Excuses, Excuses! UVa409 字符串

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

Root :: Problem Set Volumes :: Volume IV     

409 - Excuses, Excuses!

又来了一次编译错误,然后几次WA是因为分隔符不全,最后干脆把非字母全当成分隔符就AC了。 =.=


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <string.h>
using namespace std;
#define N 23
#define NLEN 73
char keywords[N][N],excuses[N][NLEN];
int sum[N];

bool bubble(int k){
	int i,j;
	char t[N];
	for (i=0;i<k-1;i++)
		for (j=0;j<k-i-1;j++)
			if (strcmp(keywords[j],keywords[j+1])>0){
				strcpy(t,keywords[j]);
				strcpy(keywords[j],keywords[j+1]);
				strcpy(keywords[j+1],t);
			}
	return true;
}

int find(char *s,int k){
	int mid,high=k-1,low=0;
	while (low<=high){
		mid=(low+high)/2;
		if (strcmp(keywords[mid],s)==0)
			return mid;
		else if (strcmp(keywords[mid],s)<0)
			low=mid+1;
		else high=mid-1;
	}
	return -1;
}

int cal(char *s,int k){
	int i,j,count=0;
	char t[NLEN];
	for (i=0;i<strlen(s);i++)
		if (isupper(s[i]))
			s[i]=tolower(s[i]);
	for(i=0,j=0;i<strlen(s);i++){
		if(!isalpha(s[i])){  
			t[j]='\0';  
			if (find(t,k)!=-1)
				count++;
			j=0;  
			continue;  
        }  
		t[j]=s[i];
		j++;  
    }
	return count;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("409in.txt","r",stdin);
#endif
	int k,e,i,max,ce=0;
	char t[NLEN];
	while (scanf("%d%d",&k,&e)!=EOF){
		ce++;
		for (i=0;i<k;i++)
			scanf("%s",keywords[i]);
		bubble(k);
		memset(sum,0,sizeof(sum));
		max=0;
		getchar();
		for (i=0;i<e;i++){
			fgets(excuses[i],NLEN-1,stdin);
			strcpy(t,excuses[i]);
			sum[i]=cal(t,k);
			if (sum[i]>max)
				max=sum[i];
		}
		printf("Excuse Set #%d\n",ce);
		for (i=0;i<k;i++)
			if (sum[i]==max)
				printf("%s",excuses[i]);
		putchar(10);
	}
	return 0;
}

UVa 409 Excuses, Excuses! (字符串匹配) 409 - Excuses, Excuses! Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=350 Judge Ito is having a problem wi 阅读详情

相关推荐

uva 409 Excuses, Excuses!字符串模拟)

也是根据题意来模拟就行了。

渐近自由 530

UVa409_Excuses, Excuses!(小白书字符串专题)

解题报告 字典树爆。 #include #include #include using namespace std; int k,e,num[100],cnt; struct node { int v; node *next[26]; }; node *newnode() { node *p=new node; p->v=0; int i;

_nplus 1048

uva409 Excuses, Excuses!字符串处理)

题目戳这里 题目大意: 给出一定量的关键词与一定量的句子,查找含有关键词量最多的句子,并输出,如果是多个句子,一并输出。 注意: 1.关键词在句子中出现必须是单词的形式,关键词是ab的时候在句子中出现的合法形式应该是:ab c 或ab,c等,abc则不算在内。 2.不区分大小写。 3.同一关键词在一个句子中多次出现只算一个。思路: 注意到以上三点,直接模拟即可,可以运用string类里

a novice 598

uva 409 Excuses, Excuses!字符串处理)

Excuses, Excuses!  Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time require

不慌不忙、不急不躁 2167

UVa409 - Excuses, Excuses!-字符串-难度2

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=350 代码+思路 #include #include #include #include #include #include #include #include us

Ieyasu的专栏 538

Excuses, Excuses! - UVa 409 哈希字符串

Excuses, Excuses! Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required listeni

提比的强行AC 894

UVA 409 - Excuses, Excuses!字符串

Excuses, Excuses!  Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time require

coco430的专栏 564

字符串训练------UVA 409题目 Excuses, Excuses!

解题思路:   其实就是比较每个字符串包含的关键字符串的个数。然后输出最多的那一串或更多串。 #include #include using namespace std; int main() { int keyCount = 0, excuseCount = 0; int index =1; while (cin>> keyCount>> excuseCount) {

Aleks 614

HDU 1606(POJ 1598 UVA 409) Excuses, Excuses!字符串匹配处理)

Excuses, Excuses! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 295    Accepted Submission(s): 138 Problem Description Judge Ito is h

风尘_浪子 2959

UVA - 409 Excuses, Excuses!

UVA - 409 Excuses, Excuses!题目大意:输入一些关键字和几句话,求出现最多个关键字的那句话,重复出现累加。解题思路:将输入打话 与关键字 匹配 累加 然后输出最多打即可#include <cstring> #include <cstdlib> #include <cstdio> int main () { int N, M; char a[1000][1000

cwb15505905513的博客 284

UVa 409 Excuses, Excuses!

/* coder: ACboy date: 2010-3-6 result: AC description: UVa 409 Excuses, Excuses!*/#include #include #include #include #include using namespace std;struct node { string str;

个人独立博客http://www.acb0y.cn/ 1410

UVA-409 Excuses, Excuses!

UVA-409 Excuses, Excuses!题目大意:先输入 x 个单词,再输入 y 个句子。统计 y 个句子中哪个含有最多单词,输出含有最多单词的句子。若相等,则一同输出。Sample Input 5 3 dog ate homework canary died My dog ate my homework. Can you believe my dog died after

Tochase的博客 239

UVA 409 (暑假-字符串(2) -B - Excuses, Excuses!)

#include #include int main() { int MAX = 0; char str[25][25], str1[25][25]; char str2[25][1700], str3[25][1700]; int m, n, t = 0; //输入数据 while (scanf("%d%d", &m, &n) != EOF) { MAX =

Bingo 1736

字符串总结

做了几个字符串的题,在此总结一下几点要注意的问题: (1)输入输出,本人习惯用gets,puts(虽然gets有漏洞),其中gets会读入缓存区的'\n',故gets前先要getchar一下,gets会读入行尾的‘\n’,而scanf("%s",s)不能读入空格、tab和'\n'; (2)操作时,注意strlen(s)可以返回s的全部字符长度,而字符串实际存储长度是strlen(s)+1;

江渚渔樵的专栏 311

UVA 题目409 - Excuses, Excuses!

Excuses, Excuses!  Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required

落日小屋 3617

UVA - 409 - Excuses, Excuses

#include #include #include #include #include #include using namespace std; const int MAXN = 20; void fun_str(string &str) { for ( int i=0; i<str.length(); i++ ) { if ( isalpha(str[i]) )

slashXX in the sky 502
上一篇: Palindromes UVa401 字符串
下一篇: Stock Chase hdu3357 图论
花酱_
博客等级 码龄14年 30粉丝 100原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值