题解

216 条题解

  • 0
    @ 2016-11-14 20:29:25

    宇宙第一水题
    var i,j,n,x,t:longint;
    begin
    readln(n,x);t:=0;
    for i:=1 to n do begin
    j:=i;
    while j>0 do begin
    if j mod 10=x then t:=t+1;
    j:=j div 10;
    end;
    end;
    writeln(t);
    end.

  • 0
    @ 2016-10-20 14:47:16
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main(){
        int n,x,wei[9],num(0);
        scanf("%d%d",&n,&x);
        for(int i(1);i<=n;i++){
            int k(i),j=1;
            while(k){
                wei[j]=k%10;
                (x==wei[j++])?num++:0;
                k/=10;
            }
            memset(wei,0,sizeof(wei));***记得清零***
        }
        printf("%d\n",num);
        return 0;
    }
    
    • @ 2016-10-20 14:47:52

      记得清零

  • 0
    @ 2016-10-08 20:06:26

    #include <iostream>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <cstdlib>
    using namespace std;

    int d[10000005];

    int main() {
    int n, x, ans=0;
    cin >> n >> x;

    d[x]=1;
    for (int i=1;i <= n;i++) {
    d[i]=d[i%10];
    if (i/10) d[i]+=d[i/10];
    ans+=d[i];
    }

    cout << ans;

    return 0;
    }

    dp大法,d[i]=d[个位]+d[各位前面的数];

  • 0
    @ 2016-09-10 13:52:20
    #include<iostream>
    using namespace std;
    int main(){
        long long ans=0,x,n,i,temp;
        cin>>n>>x;
        for(i=1;i<=n;++i){
            temp=i;
            do{
                if(temp%10==x) ++ans;
                temp/=10;
            }while(temp);
        }
        cout<<ans;
        return 0;
    }
    
  • 0
    @ 2016-08-30 13:25:05

    ###__DP大法__
    ```c++
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 39652 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 39648 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 39648 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 39648 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 39648 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 39648 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 39648 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 39648 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 39648 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 39648 KiB, score = 10
    Accepted, time = 0 ms, mem = 39652 KiB, score = 100
    代码
    #include <cstdio>
    int dp[10000001],n,x,sum = 0;
    int main() {
    scanf("%d%d",&n,&x);
    dp[x] = 1;
    for (int i = 1;i <= n;i++) {
    dp[i] = dp[i%10];
    if (i/10) dp[i] += dp[i/10];
    sum += dp[i];
    }
    printf("%d",sum);
    return 0;
    }
    ```

  • 0
    @ 2016-08-27 18:35:58

    我的pascal代码如下:

    var n,i,t:longint;
    j,x:integer;
    ch:char;
    s:string;
    begin
    t:=0;
    read(n,x);
    ch:=chr(x+ord('0'));
    for i:=1 to n do
    begin
    str(i,s);
    for j:=1 to length(s) do
    if ch=s[j] then inc(t);
    end;
    writeln(t);
    end.

  • 0
    @ 2016-08-25 22:23:06

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

  • 0
    @ 2016-08-24 17:13:39
    #include <cstdio>
    using namespace std;
    void count_num(int a,int x)
    {
        int count[10] = {0};
        int n = 1;
        int zero = 0;
        int weishu = 0;
        while(a/n)
        {
            weishu++;
            int lowp = a - (a/n)*n;
            int curr = (a/(n))%10;
            int highp = a/(n*10);
            for (int i = 0;i<10;i++)
            {
                if (i<curr)
                {
                    count[i] += (highp+1)*n;
                }
                else if (i == curr)
                {
                    count[i] += (highp)*n;
                    count[i] += (lowp+1);
    
                }
                else
                {
                    count[i] += (highp)*n;
                }
            }
            n *=10;
        }
        int t = 1;
        while(t<=weishu)
        {
            n /=10;
            zero += t*(n-1 -n/10 +1);
            t++;
        }
        count[0] -=zero;
        printf("%d",count[x]);
    }
    int main(){
        int n,x;
        scanf("%d%d",&n,&x);
        count_num(n,x);
    }
    

    感觉像吃了翔,老犯错,最后终于0ms

  • 0
    @ 2016-08-23 18:30:29

    Pascal超短代码
    var n,i,j:longint; s:string; x:char;
    a:array ['0'..'9'] of longint;
    begin
    readln(n,x,x);
    for i:=1 to n do
    begin
    str(i,s);
    for j:=1 to length(s) do
    inc(a[s[j]]);
    end;
    write(a[x]);
    end.

  • 0
    @ 2016-07-13 10:32:20

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main(){
    int n,x;
    int count=0;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    {
    int k=i;
    do{
    if(k%10==x)count=count+1;

    k=k/10;
    }while(k);

    }
    cout<<count;
    return 0;
    }

  • 0
    @ 2016-07-12 22:18:08

    给大家一个数字转字符串的函数
    str(x,s);
    x---数字 s---字符串
    例:str(123,s);
    则s='123'

  • 0
    @ 2016-07-12 22:12:22

    program ym;
    var n,m,l,s,i,j:longint;
    a,t:string;
    begin
    readln(n,m);
    a:=chr(m+48);
    s:=0;
    for i:=1 to n do
    begin
    str(i,t);
    l:=length(t);
    for j:=1 to l do
    if t[j]=a then s:=s+1;
    end;
    write(s);
    end.

  • 0
    @ 2016-07-11 11:44:12

    var
    n,x,i,sum:longint;
    s:ansistring;
    procedure ok(s:ansistring);
    var j:longint;
    begin
    for j:=1 to length(s) do
    if s[j]=chr(x+48) then inc(sum);
    end;
    begin
    readln(n,x);
    for i:=1 to n do
    begin
    str(i,s);
    ok(s);
    end;
    writeln(sum);
    end.

    过程部分把s[j]=chr(x+48)写成了s[j]='1',没过,以为longint不行,开int64没去编译过就交上去,结果有没过~~~如此水的题目,我竟然测了三次。。。太失败了

  • 0
    @ 2016-05-18 20:33:19

    小田君又来发题解啦~~~
    简单的计数问题,附代码:
    #include <cstdio>

    int Count(int n,int x){
    int cnt = 0;
    while(n != 0){
    if(n%10 == x) cnt++;
    n /= 10;
    }
    return cnt;
    }

    int main(){
    int n,x,cnt = 0;
    scanf("%d %d",&n,&x);
    for(int i = 1; i <= n; i++) cnt += Count(i,x);
    printf("%d",cnt);

    return 0;
    }

  • 0
    @ 2016-05-02 18:06:45

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int cnt=0;
    int getx(int x,int i){
    int cnt1=0;
    while(i>0){
    if(i%10==x)
    cnt1++;
    i/=10;
    }
    return cnt1;
    }
    int main(){
    int n,x;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    cnt+=getx(x,i);
    cout<<cnt;
    return 0;
    }

  • 0
    @ 2016-04-12 22:06:26

    var n,x,i,j,num:longint; s:string;
    begin
    readln(n,x); num:=0;
    for i:=1 to n do
    begin
    str(i,s);
    for j:=1 to length(s) do
    if s[j]=chr(48+x) then
    inc(num);
    end;
    writeln(num);
    end.

  • 0
    @ 2016-04-08 19:05:16

    【水】【C】
    #include<stdio.h>
    int main()
    {
    int n,x,i,j,a,ans=0,mod=1;
    scanf("%d%d",&n,&x);
    for(i=1;i<=n;i++)
    {

    a=i;
    while(a>0)
    {
    if(a%10==x) ans++;
    a=a/10;
    }
    }
    printf("%d",ans);
    return 0;
    }

  • 0
    @ 2016-02-22 13:33:22

    正则表达式就是好用


    import java.io.*;
    import java.util.*;
    import java.util.regex.*;
    public class Main {
        public static void main(String[] args) {
            Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
            final int end=sc.nextInt();
            int count=0;
            Pattern p=Pattern.compile(sc.next());
            for (int i = 1; i <=end; i++) {
                Matcher m=p.matcher(Integer.toString(i));
                while(m.find())
                    count++;
            }
            System.out.println(count);
        }
    }
    
  • 0
    @ 2016-02-19 12:56:56

    整个题目归功于sprintf
    c
    #include <stdio.h>
    int main(){
    int n,num,i,j,ans = 0;
    scanf("%d %d",&n,&num);
    char s[1000010];
    for(i = 1;i<=n;i++){
    sprintf(s+1, "%d",i);
    for(j = 1;s[j];j++)
    if(s[j] == num+48) ans++;
    }
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2016-02-18 11:16:38

    题解

    ```
    /* ***********************************************
    Author :guanjun
    Created Time :2016/2/18 11:03:23
    File Name :vijosp1848.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10000+10
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;

    bool cmp(int a,int b){
    return a>b;
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    int n,x,a;
    while(cin>>n>>x){
    ll num=0;
    for(int i=1;i<=n;i++){
    a=i;
    //cout<<a<<endl;
    while(a>0){
    if(a%10==x)num++;
    a/=10;
    }
    }
    printf("%lld\n",num);
    }
    return 0;
    }

信息

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