Wizard of Orz CodeForces - 1467A

Wizard of Orz CodeForces - 1467A

题意:

有个长度为n初始状态下各元素均为0的数组,没过一秒数组中所有元素都会+1,如果是9则会变成0,即0-9不断循环。现在你能够在开始后的任意时间点选取任意一个位置,改位置上的数字立刻停止增加,与其距离为x的位置上的元素则在x秒后暂停(这x秒内还是数字会继续增加)。给定你长度n,求出由n个元素构成的最大数字(包含前导零)

题解:

规律题,通过找规律不难发现前三位是989,从第四位开始就是0~9的循环

代码:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
inline int read(){
    
    
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){
    
    if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);
   return s*w;
}
int main()
{
    
    
	int t;
	cin>>t;
	while(t--)
	{
    
    
		int n;
		cin>>n;
		if(n==1)cout<<9<<endl;
		else if(n==2)cout<<98<<endl;
		else 
		{
    
    
			cout<<9<<8<<9; 
			for(int i=0;i<n-3;i++)
			{
    
    
				cout<<i%10;
			}
			cout<<endl;
		}
	}
	return 0;
}
/*
888
989

8888
9890

88888
98901

8888888
98901
*/

猜你喜欢

转载自blog.csdn.net/qq_35975367/article/details/114096138