Discuz! Board

 找回密码
 立即注册
查看: 130|回复: 2

老师,那个10怎么表示1啊,还有那个11怎么表示两个1

[复制链接]

15

主题

16

帖子

24万

积分

论坛元老

Rank: 8Rank: 8

积分
241078
发表于 2024-5-18 16:50:33 | 显示全部楼层 |阅读模式
#include <bits/stdc++.h>
using namespace std;
int main()
{
        int n,x,s=0;
        cin>>n>>x;
        for (int i=1;i<=n;i++)
        {
                if(i==x || i%10==x )s++;
        }
        cout<<s;
        return 0;
}

回复

使用道具 举报

660

主题

846

帖子

243万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2435559

烈空座 Lv:100
发表于 2024-5-18 20:26:41 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
        int n,x,s=0;
        cin>>n>>x;
        
        
        while(1)
        {
                if(n%10==x) s++;
                n=n/10;
                if(n==0) break;
                }
        
        cout<<s;
        return 0;
}

如果你是想找 整数n 里有几个x,可以这么做
但这只是解决 n里有几个x 的问题
1到n里有几个x需要你再认真考虑一下
回复

使用道具 举报

18

主题

22

帖子

23万

积分

论坛元老

Rank: 8Rank: 8

积分
235415

三地鼠 Lv:50
发表于 2024-5-23 21:02:42 | 显示全部楼层
#include <bits/stdc++.h>
using namespace std;
int main()
{
        int n,x,s=0;
        cin>>n>>x;
         
        for(int i=0;i<n;i++)
        {
                        while(1)
                {
                        if(n%10==x) s++;
                        if(n/10==x) s++;
                        n--;
                        if(n==0) break;
                }
        }
        cout<<s;
        return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-5-29 22:40 , Processed in 0.065349 second(s), 38 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

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