找规律(丐版)
查看原帖
找规律(丐版)
1400690
sybs1145楼主2024/10/27 17:28

笑死,赛时卡俩小时,回来秒AC,其实就是找规律板子题,写一个函数直接暴力,找一下规律

int a[] = {6,2,5,5,4,5,6,3,7,6};
int cnt(int x)
{
	int ans = 0;
	while(x>0)
	{
		ans+=a[x%10];
		x/=10;
	}
	return ans;
}

话不多说,上代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s[]={"","-1","1","7","4","2","6","8","10","18","22","20","28","68","88"};
string x[] = {"108","188","200","208","288","688","888"};
ll T,n;
int main()
{
   cin>>T;
   while(T--)
   {
       cin>>n;
       if(n<15)
       {
           cout<<s[n]<<endl;
       }
       else
       {
           cout<<x[(n-15)%7];
           for(int i = 1;i<=(n-15)/7;i++)
               cout<<"8";
           cout<<endl;
       }
   }
   return 0;
}
2024/10/27 17:28
加载中...