Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
暴力过的,供参考,求优化#include<stdio.h> #include<string.h> char bottom[110],top[100]; int mini(int a,int b) { if(a<b) return a; else return b; } int main() { int min,la,lb,i,j,flag,i1,j1; gets(bottom); gets(top); la=strlen(bottom); lb=strlen(top); min=la+lb; for(i=0,j=lb-1;i<la;i++) { flag=1; for(i1=i,j1=j; i1>=0 && j1>=0; i1--,j1--) if(bottom[i1]-'0'+top[j1]-'0'==4) { flag=0; break; } if(flag && la+lb-mini(i+1,lb)<min) min=la+lb-mini(i+1,lb); } for(j=0,i=la-1;j<lb;j++) { flag=1; for(i1=i,j1=j; i1>=0 && j1>=0; i1--,j1--) if(bottom[i1]-'0'+top[j1]-'0'==4) { flag=0; break; } if(flag && la+lb-mini(j+1,la)<min) min=la+lb-mini(j+1,la); } printf("%d\n\n",min); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator