1 条题解
-
0
C :
#include<stdio.h> int main() { int n,i,t,s=0,x; scanf("%d%d",&n,&x); for(i=1;i<=n;i++) { t=i; while(t!=0) { if(t%10==x) s++; t=t/10; } } printf("%d",s); return 0; }C++ :
#include <bits/stdc++.h> using namespace std; int main(){ int i,n,x,t,c = 0; cin>>n>>x; for(i = 1;i <= n;i++){ t = i; while(t != 0){ if(t % 10 == x){ c++; } t = t / 10; } } cout<<c<<endl; }Java :
import java.util.Scanner; public class Main { public static void main(String[] Args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int b = 0; int s = 0; int k = 0; for(int j = 1; j<=n ; j++) { b = j; while(b!=0){ s = b%10; b = b/10; if(s == m) k++; } } System.out.println(k); } }Python :
# 接收两个字符串数字,放入列表s中 s = input().split() # 字符串数字转化为整数,n表示整数,x表示要统计的数字 n = int(s[0]) x = int(s[1]) # 初始化计数c c = 0 for i in range(1, n + 1): a = i #短除法拆位,如果得出的数==x,则计数c自加1 while a > 0: s = a % 10 a //= 10 if s == x: c += 1 print(c)
- 1
信息
- ID
- 449
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者