题解

213 条题解

  • 0
    @ 2017-08-13 11:41:19

    var
    i,j,k,m,n,p,ans:longint;
    x:string;
    a:array[1..1000000]of string;
    begin
    read(n,m);
    str(m,x);
    for i:=1 to n do str(i,a[i]);
    for i:=1 to n do
    begin
    k:=length(a[i]);
    for j:=1 to k do
    begin
    p:=pos(x,a[i]);
    if p<>0 then inc(ans);
    delete(a[i],1,p);
    end;
    end;
    writeln(ans);
    end.

  • 0
    @ 2017-08-08 23:10:21

    use std::io;

    pub fn main() {
    let mut input1 = String::new();
    let n :i32;
    let x :i32;
    let mut k :i32 = 0;
    let mut j :i32;

    match io::stdin().read_line(&mut input1){
    Ok(n) => {
    //println!("{} bytes read",n);
    //println!("{}",input1);
    }
    Err(error) => println!("error:{}", error),
    }

    let v:Vec<&str> = input1.trim().split(' ').collect();
    n = v[0].parse::<i32>().unwrap();
    x = v[1].parse::<i32>().unwrap();
    for i in 1..(n+1) {
    j=i;
    while j != 0 {
    if j%10 == x { k+=1;}
    j = j/10;
    }
    }
    println!("{}",k);
    //println!("input:{}",x);
    }

  • 0
    @ 2017-08-08 23:09:44

    use std::io;

    pub fn main() {
    let mut input1 = String::new();
    let n :i32;
    let x :i32;
    let mut k :i32 = 0;
    let mut j :i32;

    match io::stdin().read_line(&mut input1){
    Ok(n) => {
    //println!("{} bytes read",n);
    //println!("{}",input1);
    }
    Err(error) => println!("error:{}", error),
    }

    let v:Vec<&str> = input1.trim().split(' ').collect();
    n = v[0].parse::<i32>().unwrap();
    x = v[1].parse::<i32>().unwrap();
    for i in 1..(n+1) {
    j=i;
    while j != 0 {
    if j%10 == x { k+=1;}
    j = j/10;
    }
    }
    println!("{}",k);
    //println!("input:{}",x);
    }

  • 0
    @ 2017-08-07 10:47:06

    蛮简单的。。。一遍AC。。。自己参考
    #include<stdio.h>
    #include<iostream>
    using namespace std;
    int main()
    {
    int n,x,r,q,num=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
    {
    int temp=i;
    do
    {
    r=temp%10;
    q=temp/10;
    if(r==x) num++;
    temp=q;
    }while(q!=0);
    }
    cout<<num;
    }

  • 0
    @ 2017-07-11 22:10:56

    #include<iostream>
    using namespace std;
    int main ()
    {
    int x,y,s=0;
    cin>>x>>y;
    for(int i=1;i<=x;i++)
    {int k=i;
    do
    {if(k%10==y)s++;
    k=k/10;
    }
    while(k>=1);
    }
    cout<<s;
    return 0;
    }

  • 0
    @ 2017-07-10 19:22:11

    #include<cstdio>
    int main()
    {
    int num=0;
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
    int j=i;
    while(j>=1)
    j%10==m?num++,j/=10:j/=10;
    }
    printf("%d",num);
    }

  • 0
    @ 2017-07-10 19:16:42

    #include<cstdio>
    int main()
    {
    int n,m=0;
    scanf("%d",&n);
    while(n!="#")
    {
    if(n/10=1)
    m+=1;
    scanf("%d",&n);
    }
    printf("%d",m);
    return 0;
    }

  • 0
    @ 2017-07-10 09:47:08

    pascal 神奇的字符串做法

    var n,x,l,i,j,t:longint;s1,s:string;
    begin
        read(n,x);str(x,s1);t:=0;
        for i:= 1 to n do begin
            str(i,s);l:=length(s);
            j:=0;
            repeat
                j:=j+1;
                if s[j]=s1 then t:=t+1;
            until j=l;
        end;
        write(t);
    end.
    
  • 0
    @ 2017-07-02 13:10:45

    我的pascal
    var
    n,x,i,y,z:longint;
    begin
    y:=0;
    read(n,x);
    for i:= 1 to n do
    begin
    z:=i;
    while z>0 do
    begin
    if z mod 10=x
    then y:=y+1;
    z:=z div 10;
    end;
    end;
    write(y);
    end.

  • 0
    @ 2017-06-30 12:03:13
    #include<stdio.h>
    int main()
    {
        int num=0;
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
        {
            int j=i;
            while(j>=1)
            j%10==m?num++,j/=10:j/=10;
        }
        printf("%d",num);
    }
    
  • 0
    @ 2017-06-30 12:02:39
    #include<stdio.h>
    int main()
    {
        int num=0;
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
        {
            int j=i;
            while(j>=1)
            j%10==m?num++,j/=10:j/=10;
        }
        printf("%d",num);
    }
    
  • 0
    @ 2017-06-24 20:14:11

    Python AC
    Python
    a,b = raw_input().split()
    count = 0
    for i in range(1,int(a)+1):
    count += str(i).count(b)
    print count

  • 0
    @ 2017-06-23 15:28:11
    //
    // Created by JimmyChen on 6/23/17.
    //
    
    #include <cstdio>
    #include <iostream>
    
    using namespace std;
    int a, num;
    
    int main(){
        cin >> a >> num;
        int count = 0;
        for (int i = 1; i <= a; i++){
            int temp = i;
            while (temp > 0){
                if (temp % 10 == num){count++;}
                temp = temp / 10;
            }
        }
        printf("%d", count);
    }
    
  • 0
    @ 2017-06-20 21:36:40

    #include <iostream>
    #include <cmath>

    using namespace std;

    int main() {
    int n = 0, x = 0;
    cin >> n >> x;
    int dig = 1, nowdig = 0, res = 0, lev = 0, num = n, zlev = 0;
    while (n>0) {
    nowdig = n % 10;
    if (!lev) {
    if (nowdig >= x&&n>10) {
    res = 1;
    }
    else res = 0;
    }
    else {
    if (n < 10 && !x) {
    res += (nowdig - 1)*lev+zlev;
    }
    else {
    res += nowdig*lev;
    if (nowdig > x)res += pow(10, dig - 1);
    else if (nowdig == x) {
    int tmp = pow(10, dig);
    if (x > 0) {
    res += (num%tmp - nowdig*tmp / 10 + 1);
    }
    else {
    res += num%tmp+1;
    }
    }
    }
    }
    if (!x)zlev += 9 * lev;
    lev *= 10;
    lev += pow(10, dig - 1);
    dig++;
    n /= 10;
    }
    cout << res << "\n";
    return 0;
    }

  • 0
    @ 2017-06-16 18:39:12
    #include <cstdio>
    #include <string>
    #include <sstream>
    
    using namespace std;
    /*
        Created and edited by Ray Eldath.
    */
    int main() {
        int r[10];
        for (int i=0; i<10; i++)
            r[i]=0;
        int a, b;
        scanf("%d%d", &a, &b);
        stringstream ss;
        for (int i = 1; i <= a; i++)
            ss << i;
        string s = ss.str();
        for (int i = 0; i < s.size(); i++)
            r[s[i] - '0']++;
        printf("%d", r[b]);
    }
    
  • 0
    @ 2017-06-07 22:40:14

    这题似乎没什么好说的,大概就是用模运算加判定吧。
    主要是这题的题目的检测有问题,不然我这代码应该过不了,比如n给一个1000,我这代码就炸了……

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int i,n,x,k=0,j; //k为总数 
        cin >>n>>x;
        for(i=1;i<=n;i++)
        {
            j=i;
            while(j)
            {
                if(j%10==x)
                k++;
                j=j/10;
            }
        }
        cout<<k;
        return 0;
    }
    
  • 0
    @ 2017-05-31 18:48:08

    这是一道水题,只要跟着题目要求模拟一遍就OK了,好了不多说了,直接上代码
    #include <bits/stdc++.h>
    using namespace std;
    int n, m, a;
    int cnt = 0;
    int main()
    {
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
    {
    a = i;
    while(a > 0)
    {
    if(a % 10 == m)
    {
    cnt++;
    }
    a = a / 10;
    continue;
    }
    }
    cout << cnt << endl;
    return 0;
    }

  • 0
    @ 2017-05-29 21:42:26

    #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;
    }

  • 0
    @ 2017-05-26 11:25:26

    #include <cstdio>
    #include <iostream>
    using namespace std;
    int main() {
    int i,j,x,n;
    int a[10]={0};
    cin>>n>>x;
    for(i=1;i<=n;i++){
    j=i;
    while(j>0){
    a[j%10]++;
    j/=10;
    }

    }
    cout<<a[x];
    return 0;
    }

  • 0
    @ 2017-05-23 20:11:16

    用c++写的,思路是用一个递归函数处理每个数,然后用for循环处理全部的数

    #include <iostream>
    
    long int count(long int temp, long int x);
    
    int main()
    {
        long int n, x, result=0;
        std::cin >> n >> x;
        for(long int i=1;i<=n;i++)
        {
            result+=count(i, x);
        }
    
        std::cout << result << std::endl;
    
        return 0;
    }
    
    long int count(long int temp, long int x)
    {
        if(temp/10 < 1)
        {
            if(temp == x)
            {
                return 1;
            }else
            {
                return 0;
            }
        }else
        {
            if(temp%10 == x)
            {
                return 1 + count(temp/10, x);
            }else
            {
                return 0 + count(temp/10, x);
            }
        }
    }
    

信息

ID
1848
难度
5
分类
(无)
标签
递交数
16580
已通过
5806
通过率
35%
被复制
36
上传者