213 条题解
-
0IMUT201720206042 LV 5 @ 2018-03-27 19:33:26
#include<iostream>
#include<cstdio>
using namespace std;int main() {
int n, num, i, t, a;
int sum = 0;
scanf("%d %d", &n, &num);
t = n;
for(i = 1; i <= n; i++) {
a = i;
while(a) {
if(a%10==num)
sum++;
a /= 10;
}
}
printf("%d", sum);
} -
02018-03-18 20:26:13@
纯模拟题,建议C、C++蒟蒻练手。
#include<bits/stdc++.h> using namespace std ; //Vijos P1848 int x , y , ans ; int num(int n) { int ans = 0 ; while (n > 0)//枚举n的每一位上的数 { if (y == n % 10) ans ++ ;//求个数 n /= 10 ; } return ans ;//返回个数 } int main() { cin >> x >> y ; for (int i = 1 ; i <= x ; i ++) { ans += num(i) ;//枚举,累加个数 } cout << ans ; return 0 ; }
-
02018-03-16 15:21:28@
Java版
import java.util.Scanner;public class Main
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
String str=scan.nextLine();
String s=" ";
String[] s1=str.split(s);
int n=Integer.valueOf(s1[0]);
int x=Integer.valueOf(s1[1]);
int num=0;
for(int i=1;i<=n;i++)
{
String ss=String.valueOf(i);
char[] ch=ss.toCharArray();
for(int j=0;j<ch.length;j++)
{
String s2=String.valueOf(ch[j]);
int a=Integer.valueOf(s2);
if(a==x)
{
num++;
}
}
}
System.out.println(num);
}}
-
02018-03-14 23:27:51@
搜索x==0为止 之前每次搜索到一个满足的数字 ans ++
注意ans要开在函数前面
下面是代码#include <cstdio> using namespace std; int ans; void xx(int n, int x){ if(x == 0) return; if(x % 10 == n) ans ++; xx(n, x /= 10); } int main(){ int n, x; scanf("%d%d", &x, &n); for(int i = 1; i <= x; ++ i) xx(n, i); printf("%d", ans); return 0; }
-
02018-02-11 15:29:20@
#include <stdio.h>
int main()
{
int i,n,x,k=0,j;
scanf("%d %d",&n,&x);
for(i=1;i<=n;i++)
{
j=i;
while(j)
{
if(j%10==x)
k++;
j=j/10;
}
}
printf("%d",k);
return 0;
} -
02018-02-09 17:13:13@
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int x = scanner.nextInt();
String j = String.valueOf(x);
Pattern pa = Pattern.compile(j);
int count = 0;
for(int i=1;i<=n;i++){
String str = String.valueOf(i);
Matcher ma = pa.matcher(str);
while(ma.find()){
count ++;
}
}
System.out.println(count);
scanner.close();
}}
-
02018-02-08 22:58:50@
import java.io.*;
import java.util.*;public class Main
{
public static void main(String[] args) throws IOException {
Main main = new Main();
System.out.println(main.getNs(main.x, main.n));
}private int x;
private int n;public Main(){
Scanner sc = new Scanner(System.in);
x = sc.nextInt();
n = sc.nextInt();
}public int getNs(int x, int n){
int counts;
int sum = 0;
int num = 0;
int mod = 0;for(int i = x ; i > 0 ; i--){
num = i;
counts = 0;
while(num > 0){
mod = num % 10;
num /= 10;
if(mod == n ){
counts++;
}
}
sum += counts;
}
return sum;
}
} -
02018-02-08 15:58:25@
数学小方法
#include<cstdio> #include<cmath> int main(){ int n,x,b=7,o,k; scanf("%d%d",&n,&x); while(n<=pow(10,--b)); o=b*pow(10,b-1); for(k=pow(10,b);k<=n;k++){ int j=k; while(j){ if(j%10==x)o++; j/=10; } } if(x==0)while(b--)o-=pow(10,b); printf("%d",o); return 0; }
-
02018-02-01 21:44:37@
水题使人快乐.
#include <iostream> using namespace std; int finder(int num,int target){ int timer=0; while(num>=10){ int x=num%10; if(x==target) timer++; num=(num-x)/10; } if(num==target) timer++; return timer; } int main(){ int n,target,i,ans=0; scanf("%d%d",&n,&target); for(i=1;i<=n;i++) ans+=finder(i,target); printf("%d",ans); return 0; }
-
02018-01-31 11:19:04@
差点被0关了
import java.util.Scanner; public class Main { static int n = 0; static int choice = 0; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int max = scan.nextInt(); choice = scan.nextInt(); findTime(max); System.out.println(n); scan.close(); } public static void findTime(int max) { if (max >= choice && choice > 0) { n++; } for (int i = choice + 1; i <= max; i++) { findNum(i); } } public static void findNum(int num) { if (num < 10) { if (num == choice) { n++; } return; } else { int mod = num % 10; if (mod == choice) { n++; } findNum(num / 10); } } }
-
02018-01-18 17:07:44@
#include <iostream>
using namespace std;
int main()
{
int n,x,count=0;
cin>>n>>x;
for(int i=1;i<=n;i++)
{
int a=i;
while(a>0)
{
int s=a%10;
a=a/10;
if(s==x)
count++;
}
}
cout<<count;
return 0;
} -
02018-01-14 00:37:02@
#include<stdio.h>
int main(void){
int n,x,i=0,j=0,m,yu=0,end=0,a[50]={0};
scanf("%d %d",&n,&x);
for(i=1;i<=n;i++){
j=0; //reset j
yu=i;
while(yu>=10){
a[j]=yu%10; //循环用来求数的每一位上的数值
yu=yu/10;
j++;
}
a[j]=yu;
m=j;
for(j=0;j<=m;j++){
if(a[j]==x){
end++;
}
}
}
printf("%d\n",end);
return 0;
} -
02017-12-31 15:41:37@
#1 Accepted 103ms 11.305 MiB
#2 Accepted 87ms 9.141 MiB
#3 Accepted 122ms 9.23 MiB
#4 Accepted 106ms 11.055 MiB
#5 Accepted 158ms 8.969 MiB
#6 Accepted 119ms 9.223 MiB
#7 Accepted 91ms 11.328 MiB
#8 Accepted 123ms 11.051 MiB
#9 Accepted 107ms 9.328 MiB#10 Accepted 148ms 9.121 MiB
using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
string[] sn = str.Split(' ');
int n = int.Parse(sn[0]);
int x = int.Parse(sn[1]);
int count = 0;
for (int i = 1; i <=n; i++)
{
int num = i;
while(num>0)
{
if (num % 10 == x)
count++;
num/=10;
}
}
Console.WriteLine(count);
}
}
} -
02017-12-25 17:40:31@
//一道简单的取数判断题
#include <iostream>
using namespace std;int main()
{
long int n;//定义一个n,作为要输入的1到n
int x,i=1,a,b=0,z=0;
cin>>n>>x;
for(;i<=n;i++)
{a=i;//把外循环的1-n次每个数 都赋给a然后进行判断
while(a)
{ b=a%10;//a的余数的值赋给b,意思就是取个位数
if(b==x)//进行判断若b是否等于所输入的x,
z++;//满足,则计数器z
a=a/10;
}//然后让a/10继续进行判断直到a=0结束while循环
//然后跳回外循环进行第二个数的判断
}cout<<z<<endl;
return 0;
} -
02017-12-25 17:40:18@
//一道简单的取数判断题
#include <iostream>
using namespace std;int main()
{
long int n;//定义一个n,作为要输入的1到n
int x,i=1,a,b=0,z=0;
cin>>n>>x;
for(;i<=n;i++)
{a=i;//把外循环的1-n次每个数 都赋给a然后进行判断
while(a)
{ b=a%10;//a的余数的值赋给b,意思就是取个位数
if(b==x)//进行判断若b是否等于所输入的x,
z++;//满足,则计数器z
a=a/10;
}//然后让a/10继续进行判断直到a=0结束while循环
//然后跳回外循环进行第二个数的判断
}cout<<z<<endl;
return 0;
} -
02017-12-18 14:47:30@
#include <iostream> using namespace std; int main() { int n,x,j,cnt=0; cin>>n>>x; for(int i=1;i<=n;i++) { j=i; while(j) { if(j%10==x)cnt++; j/=10; } } cout<<cnt<<endl; return 0; }
-
02017-12-11 20:15:20@
思路很简单,直接求出1~n每个数的x出现次数。。。
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
void check(int z){
int a[15],zx=z,p=-1;
while(zx!=0){
p++;
a[p]=zx%10;
zx/=10;
}
for(int i=0;i<=p;i++)
if(a[i]==x) ans++;
return;
}
int main(){
scanf("%d%d",&n,&x);
for(int i=1;i<=n;i++) check(i);
printf("%d\n",ans);
return 0;
} -
02017-12-06 15:57:15@
n, x = raw_input().split()
print sum([str(i+1).count(x) for i in range(int(n))]) -
02017-11-23 13:45:02@
int a[10]; int main(){ int n,x; scanf("%d%d", &n, &x); for(int i=1; i<=n; i++){ int k=i; while(k){ a[k%10]++; k/=10; } } printf("%d", a[x]); return 0; }
-
02017-11-19 12:22:34@
Haskell到达战场
main=print.(\(n:x:[])->sum.map(length.filter(\n->read[n]==x).show)$[1..n]).map read.words=<<getLine
可惜上面这种会超时,只能改成下面这个:
solve :: Int -> Int -> Int solve 0 _ = 0 solve num x = number num x + solve (num - 1) x number :: Int -> Int -> Int number 0 _ = 0 number num x | num `mod` 10 == x = 1 + number (num `quot` 10) x | otherwise = number (num `quot` 10) x main :: IO() main = print . (\(a:b:[])->solve a b) . map read . words =<< getLine
信息
- ID
- 1848
- 难度
- 5
- 分类
- (无)
- 标签
- 递交数
- 16580
- 已通过
- 5806
- 通过率
- 35%
- 被复制
- 36
- 上传者