【打表 or 規律】ZOJ 2965 Accurately Say "CocaCola"!

題目鏈接:ZOJ 2965 Accurately Say “CocaCola”!

我先用打表做了下,也是能A的

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;

int st[111];

bool check(int x){
    if(x % 7 == 0){
        return true;
    }
    while(x){
        if(x%10 == 7){
            return true;
        }
        x /= 10;
    }
    return false;
}

void ss()
{
    memset(st, 0x3f3f3f3f, sizeof(st));
    int num = 1, cnt = 0, ptr=-0x3f3f3f3f;
    bool pre=false, cur;
    while(ptr <= 111){
        cur = check(num);
        if(cur){
            if(pre){
                cnt++;
            }else{
                cnt = 1;
            }
        }else{
            cnt = 0;
        }
        if(cnt){
            st[cnt]=min(st[cnt], num-cnt+1);
            ptr=max(ptr, cnt);
        }
        pre=cur;
        num++;
    }
}

int main(int argc, char const *argv[])
{
    // freopen("in", "r", stdin);
    ss();
    int n;
    while(scanf("%d", &n)!=EOF){
        while(n--){
        int cas;
        scanf("%d", &cas);
        printf("%d\n", st[cas]);
        }
    }
    return 0;
}

然後 發現 幾個if就能過的。。

#include<stdio.h>
void cococla(int p)
{
    if(p==1) printf("7\n");
    else if(p==2) printf("27\n");
    else if(p<=10) printf("70\n");
    else if(p==11) printf("270\n");
    else printf("700\n");
}
int main()
{
    int T,p;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&p);
        cococla(p);
    }
    return 0;
}

表示 本人智商捉急啊。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章