题目链接: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;
}
表示 本人智商捉急啊。