UVa 1588 - Kickdown(BUG)
【摘要】
//UVa 1588 - Kickdown//一次循环,分类讨论//有BUG,,,不要看了,,仅供收藏。。。欢迎大神提出意见。。。#include<stdio.h>int main(){ freopen("x3.11.in","r",stdin); //freopen("x3.11.out","w",stdout);/...
-
//UVa 1588 - Kickdown
-
//一次循环,分类讨论
-
//有BUG,,,不要看了,,仅供收藏。。。欢迎大神提出意见。。。
-
#include<stdio.h>
-
int main(){
-
freopen("x3.11.in","r",stdin);
-
//freopen("x3.11.out","w",stdout);
-
//DATE IN
-
char ch, must = 1; //ch为临时输入,must处理掩码得到0101
-
bool a[2][100]; //用于存放每次的2组数据
-
int count = 0, is = 0, lo[2],ca = 0; //count记录字符串长度并用lo[]存储,ca为答案个数
-
while((ch = getchar()) != EOF){
-
if(ch == '\n'){
-
lo[is++] = count;
-
putchar('\n');
-
//printf("size:%d\n",lo[is-1]);
-
count = 0;
-
}else {
-
if(ch == ' ')continue;
-
else{
-
a[is][count] = !(ch & must);
-
printf("%d ",a[is][count]);
-
count++;
-
}
-
}
-
-
//DATE DO(此处计算并输出答案,并在最后重置is)
-
if(is == 2){
-
int re , m = 0, iss = 0,i = lo[0];
-
//re 为重复,m向右移,iss 为开关,第i次
-
while(1){
-
if(i > 0)i--;else m++;
-
for(int j = 0; ; j++){
-
if(!m && (a[0][i+j]+a[1][j+m])==2)break;
-
if(!m && (i+j)==(lo[0]-1)){re = j+1;break;}
-
if(!i && j==(lo[0]-1)){re = lo[0];break;}
-
if(!i && (j+m+1)==lo[1]){re >= lo[1]?iss=1:re = lo[1]-m;break;}
-
if(!i && m==lo[1]){re = 0;break;}
-
}
-
if(re==lo[0] || re==lo[1] || iss==1 || re == 0){
-
printf("case%d:%d\n",++ca,lo[0]+lo[1]-re);
-
break;
-
}
-
}
-
//continue
-
is = 0;
-
}
-
}
-
return 0;
-
}
-
-
/*
-
UVa1588测试数据
-
case1:10
-
case2:4
-
case3:7
-
case4:8
-
case5:10
-
case6:8
-
case7:15
-
case8:
-
*/
以下为测试数据:
3.11.in
2 2 1 2 1 1 2
2 1 1 2 1 1 2 1 1 2
2 2
2 1 1 2
2 2 2 1
2 2 2 1
2 2 2 2
2 1 1 1 1 2
2 1 1 2 1 1 2 1 1 2
2212112
1 2 1 2 1 2 1 2
2 1 2 1 2 1 2 1
2 2 1 1 2 2 1 1 2 2
2 1 2 1 2
-
//AC1
-
#include<stdio.h>
-
#include<string.h>
-
const int maxn=100;
-
char a[maxn+1],b[maxn+1];
-
int n1,n2;
-
int min(const int &i,const int &j){
-
return i<j?i:j;
-
}
-
int minLen(char *s1,char *s2,int &n){
-
int sumLen=n1+n2, minn=min(n1,n2), len=sumLen;
-
for(int i = 0; i < n; i++){
-
int ok = 1, fix = min(n-i,minn);
-
for(int j=0; j < fix; j++)
-
if(s1[i+j]=='2'&&s2[j]=='2'){
-
ok=0; break;
-
}
-
if(ok&&len>sumLen-fix)len=sumLen-fix;
-
}
-
return len;
-
}
-
int main(){
-
while(scanf("%s%s",&a,&b)==2){
-
n1=strlen(a),n2=strlen(b);
-
printf("%d\n",min(minLen(a,b,n1),minLen(b,a,n2)));
-
}
-
}
-
//AC2
-
#include<stdio.h>
-
#include<string.h>
-
char a[110],b[110];
-
int main(){
-
while(scanf("%s%s",a,b) != EOF){
-
int i,j,t,n1,n2;
-
int temp,len1,len2;
-
i=j=t=0;
-
n1=strlen(a);
-
n2=strlen(b);
-
//
-
while(j<n1 && i<n2){
-
if(a[j]+b[i]-96<=3)i++,j++;
-
else t++,i=0,j=t;
-
}
-
len1=n1+n2-i;
-
i=j=t=0;
-
//
-
while(j<n2&&i<n1){
-
if(a[j]+b[i]-96<=3)i++,j++;
-
else t++,i=0,j=t;
-
}
-
len2=n1+n2-i;
-
printf("%d\n",len1 < len2 ? len1 : len2 );
-
}
-
return 0;
-
}
2212112
2112112112
22
2112
2221
2221
2222
211112
2112112112
2212112
12121212
21212121
2211221122
21212
文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。
原文链接:gwj1314.blog.csdn.net/article/details/54744459
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)