ZOJ2965 Accurately Say "CocaCola"! 线性扫描
Accurately Say "CocaCola"!
范围找到:1——700左右,然后打表就ok了
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
bool a[810];
int sum[810];
int pos[810];
void _judge(int v)
{
if(v%7==0){
a[v]=true;
return ;
}
int t=v,k;
while(t){
k=t%10;
if(k==7){
a[v]=true;
return ;
}
t/=10;
}
return ;
}
int main()
{
int T,n,m,i,j,Max=0;
cin>>T;
for(i=1;i<=800;i++)
_judge(i);
for(i=1;i<=800;i++)
if(a[i]) {
sum[i]=sum[i-1]+1;
if(!pos[sum[i]]) pos[sum[i]]=i;
}
for(i=1;i<=T;i++){
cin>>m;
cout<<pos[m]-m+1<<endl;
}
return 0;
}
It is your time to fight!