UVa 10192 - Vacation(LCS水题)

题目:http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1133

水题,但有个坑点。。。

坑在循环判断条件里面,如果用scanf读入来做判断条件的话就会超时,如果用gets就没问题。。。

真不知道是为什么,以前一直听说scanf挺快的,比cin快多了,没想到这次tle是因为scanf。。。我再也不相信scanf了。。。以后有字符串读入我都用gets了。。。


#include<cstdio>
#include<cstring>
const int maxn = 110;

int max(int a, int b)
{
	if (a > b)
		return a;
	return b;
}

int main()
{
	char a[maxn], b[maxn], cnt = 1;
	while (gets(a) && a[0] != '#')
	{
		gets(b);
		int c[maxn][maxn] = {0};
		int la = strlen (a), lb = strlen (b);
		for (int i = 0; i < la; i++)
			for (int j = 0; j < lb; j++)
				if (a[i] == b[j])
					c[i + 1][j + 1] = c[i][j] +1;
				else 
					c[i + 1][j + 1] = max(c[i][j + 1], c[i + 1][j]);
		printf("Case #%d: you can visit at most %d cities.\n", cnt++, c[la][lb]);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值