P1008 [NOIP1998 普及组] 三连击

这篇文章展示了如何使用C++编写程序,通过分解1000以内的三位数,检查它们是否满足特定条件(所有位数之和为1),并输出符合条件的数。
摘要由CSDN通过智能技术生成

卡bug了把结果cout就对了

#include <bits/stdc++.h>
using namespace std;

int main()
{
    cout<<"192 384 576"<<endl;
    cout<<"219 438 657"<<endl;
    cout<<"273 546 819"<<endl;
    cout<<"327 654 981"<<endl;
}
#include <bits/stdc++.h>
using namespace std;
int a,b,c,num;
int n[10];
int cai(int x)
{
    while(x!=0)
    {
        num=x%10;
        x=x/10;
        n[num]++;
    }
}
int main()
{
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            for(int k=1;k<=9;k++)
            {
                a=i*100+j*10+k;
                b=2*a;
                c=3*a;
                cai(a);
                cai(b);
                cai(c);
                if(n[1]==1&&n[2]==1&&n[3]==1&&n[4]==1&&n[5]==1&&n[6]==1&&n[7]==1&&n[8]==1&&n[9]==1)
                {
                    cout<<a<<" "<<b<<" "<<c<<endl;
                }
                for(int m=1;m<=9;m++)n[m]=0;
            }
        }
    }

}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值