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;
}
高低档,一道水题,就是考虑两个方向,然后就计算两块木板长度了。
贴代码:
#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;
}
相关文章推荐
- uva1588 Kickdow
- uva1588 Kickdown
- uva-1588
- 换低档装置(uva-1588)
- uva 1588 Kickdown
- Uva 1588 换抵挡装置
- UVA - 1588 Kickdown
- 习题3-11 换低挡装置(Kickdown, ACM/ICPC NEERC 2006, UVa1588)
- uva-1588
- UVa 1588 换抵挡装置
- UVa1588——Kickdown
- uva 1588 - Kickdown
- UVA 1588 Kickdown
- UVA 1588-Kickdown
- uva-1588
- UVa 1588 Kickdown
- UVA 1588 Kick Down
- 小紫书 3-11 UVA 1588 POJ 3158 Kickdown
- uva-1588-Kickdown
- UVA 1588_Kickdown