您的位置:首页 > 其它

Uva1588高低档

2016-09-11 23:51 120 查看
第一次写博客,标志着正式练习ACM,不再划水了,每天坚持刷题。

高低档,一道水题,就是考虑两个方向,然后就计算两块木板长度了。

贴代码:

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int main()

{
char a[100],b[100];
int la=0,lb=0;
while(scanf("%s%s",a,b)!=EOF)
{
la=strlen(a);
lb=strlen(b);
int i=0,j=0,t=0,re=0,res1=0,res2=0;
while(i<lb&&j<la)
{
if(3>=a[j]+b[i]-96)
{
i++;
j++;
}
else

              t++,i=0,j=t;
}
res1=lb+la-i;//两木板长度等于两木板长度减去重合的长度,此处的i为重合长度
i=j=t=0;
while(i<la&&j<lb)
{
if(3>=a[i]+b[j]-96)
{
i++;
j++;
}
else
t++,i=0,j=t;
}
res2=la+lb-i;
if(res1>res2) re=res2;
else re=res1;
printf("%d\n",re);
}
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: