20160323 Repeating Decimals,All in All,Kickdown

202 - Repeating Decimals

#include<cstdio>
#include<cstring>
#define maxn 3000
int num[3010],vis[3001],ap,pt=-1;
int main(){
    int a,b,s;
    while(scanf("%d%d",&a,&b)!=-1&&b){
        printf("%d/%d = ",a,b);
        ap=0;
        memset(vis,0,sizeof(vis));
        num[ap++]=a/b;a%=b;
        while(ap<=maxn){
            if(vis[a]){s=vis[a];break;}
            vis[a]=ap;
            a*=10;
            num[ap++]=a/b;
            a%=b;
        }
        printf("%d.",num[0]);
        for(int i=1;i<51;i++){
            if(i==s)printf("(");
            if(i==ap){printf(")");break;}
            printf("%d",num[i]);
        }
        if(ap>50)printf("...)");
        printf("\n   %d = number of digits in repeating cycle\n\n",ap-s);
    }
    return 0;
}
/*英语水平不够...一个格式错误调了N久...*/



10340 - All in All 


#include<cstdio>
char s[1000001],t[1000001],ok;
void dfs(int i,int k){
    if(!s[i]){ok=1;return ;}
    if(!t[k]||ok)return ;
    for(int j=k;t[j];j++)if(s[i]==t[j]){
        dfs(i+1,j+1);
    }
}


int main(){
    while(scanf("%s%s",s,t)!=-1){
        ok=0;
        dfs(0,0);
        if(ok)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}



3158 Kickdown


#include<cstdio>
#include<cstring>
#define min(x,y) (x)<(y)?(x):(y)
#define max(x,y) (x)>(y)?(x):(y)
char a[110],b[110];
int f(char*t,char*d){//top在上 ,down在下
    int ok,tl=strlen(t),dl=strlen(d),ans=tl+dl;
    for(int k=0;k<=dl;k++){//t往右移k个
        ok=1;
        for(int i=k;i<dl&&i<k+tl;i++)
        if(d[i]=='2'&&t[i-k]=='2'){ok=0;break;}
        if(ok){
            ans=min(ans,max(k+tl,dl));
        }
    }
    return ans;
}
int main(){
    while(scanf("%s%s",a,b)!=-1){
        printf("%d\n",min(f(a,b),f(b,a)));
    }
    return 0;
}



你可能感兴趣的:(紫书)