找回密码
 中文实名注册
查看: 226|回复: 3

p1. 幸运数字 (15 pts)

[复制链接]

697

主题

1085

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
22873
发表于 2022-6-5 18:35:54 | 显示全部楼层 |阅读模式
如果⼀个正整数 在五进制、七进制、九进制的表⽰下都没有数字 “0”,我们就称 是幸运
数字。例如:

样例输⼊ 1
100  1000
样例输出 1
203


样例输⼊ 2
900  4096
样例输出 2
389



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?中文实名注册

x
回复

使用道具 举报

1

主题

57

帖子

252

积分

中级会员

Rank: 3Rank: 3

积分
252
发表于 2022-6-5 18:50:16 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,cnt1=0,m[1000],s=0,j=0;
	cin>>a>>b;
	for(int i=a;i<=b;i++)
	{
		cout<<"?"<<endl;
		while(i!=0)
    	{
        	m[cnt1]=i%5;
        	cnt1++;
        	i/=5;
    	}
		while(i!=0)
    	{
        	m[cnt1]=i%7;
        	cnt1++;
        	i/=7;
    	}
    	while(i!=0)
    	{
        	m[cnt1]=i%9;
        	cnt1++;
        	i/=9;
    	}
    	for(j=0;j<cnt1;j++)
    	{
    		if(m[j]==0)
    		{
    			break;
			}
		}
		if(j==cnt1)
		{
			s++;
			j=0;
		}
	}
	cout<<s<<endl;
	return 0;
}
回复

使用道具 举报

697

主题

1085

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
22873
 楼主| 发表于 2022-6-5 19:34:19 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,cnt1=0,m[31],s=0,j=0,c,h;
    cin>>a>>b;
    
    for(int i=a;i<=b;i++)
    {
        cnt1=0;
		c=i;
        while(c!=0)
        {
            m[cnt1]=c%5;
            cnt1++;
            c/=5;
        }
		c=i;
        while(c!=0)
        {
            m[cnt1]=c%7;
            cnt1++;
            c/=7;
        }
		c=i;
        while(c!=0)
        {
            m[cnt1]=c%9;
            cnt1++;
            c/=9;
        }
        
        for(int h=cnt1-1;h>=0;h--)//从高位输出
    	cout<<m[h];
    	
    	  for(j=0;j<cnt1;j++)
        {
            if(m[j]==0)
            {
                break;
            }
        }
        if(j==cnt1)
        {
            s++;
            j=0;
        }
    	
    }
    cout<<endl;
  	cout<<s<<endl;
    return 0;
}
回复

使用道具 举报

1

主题

57

帖子

252

积分

中级会员

Rank: 3Rank: 3

积分
252
发表于 2022-6-5 19:40:33 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,cnt1=0,m[31],s=0,j=0,c,h;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        cnt1=0;
        c=i;
        while(c!=0)
        {
            m[cnt1]=c%5;

            cnt1++;

            c/=5;
        }
        c=i;
        while(c!=0)
        {
            m[cnt1]=c%7;
            cnt1++;
            c/=7;
        }
        c=i;
        while(c!=0)
        {
            m[cnt1]=c%9;
            cnt1++;
            c/=9;
        }
        for(j=0;j<cnt1;j++)
        {
            if(m[j]==0)
            {
                break;
            }
        }
        if(j==cnt1)
        {
            s++;
            j=0;
        }
    }
    cout<<s<<endl;
    return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

小黑屋|东台市机器人学会 ( 苏ICP备2021035350号-1;苏ICP备2021035350号-2;苏ICP备2021035350号-3 )

GMT+8, 2024-5-17 10:57 , Processed in 0.044113 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表