题解

60 条题解

  • 0
    @ 2016-09-13 18:58:23

    #include<bits/stdc++.h>
    using namespace std;
    string waj(int i){
    string temp;
    ostringstream oss;
    oss<<i;
    temp=oss.str();
    return temp;
    }
    int main(){
    int l,r,ans=0;
    cin>>l>>r;
    string a;
    for(int i=l;i<=r;i++){
    a+=waj(i);
    }
    for(int i=0;i<a.size();i++){
    if(a[i]=='2') ans++;
    }
    cout<<ans;
    }

  • 0
    @ 2016-09-01 19:14:41

    ###**dp**

    评测结果
    编译成功
    
    测试数据 #0: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    Accepted, time = 0 ms, mem = 552 KiB, score = 100
    代码
    #include <cstdio>
    int dp[10001],L,R,sum = 0;
    int main() {
      scanf("%d%d",&L,&R);
      dp[2] = 1;
      for (int i = 1;i <= R;i++) {
        dp[i] = dp[i%10];
        if (i/10) dp[i] += dp[i/10];
        if (i >= L) sum += dp[i];
      }
      printf("%d",sum);
      return 0;
    }
    
  • 0
    @ 2016-08-16 11:07:40

    逐位判断竟然也能0ms。。。

  • 0
    @ 2016-08-08 15:18:08

    字符串 打遍天下无敌手
    pascal
    var
    l,r,i,s,j:longint;
    s1:string;
    begin
    readln(l,r);
    for i:=l to r do
    begin
    str(i,s1);
    for j:=1 to length(s1) do
    if s1[j]='2'
    then
    inc(s);
    end;
    writeln(s);
    readln;
    end.
    `

  • 0
    @ 2016-02-24 13:27:38

    var n,m,i,s,j:longint;
    st:string;
    begin
    readln(n,m);
    for i:=n to m do
    begin
    str(i,st);
    for j:=1 to length(st) do
    if st[j]='2' then inc(s);
    end;
    writeln(s);
    end.

  • 0
    @ 2016-02-21 22:42:42
    import java.util.Scanner;
    public class Main {
    
        public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            String str;
            StringBuffer sb=new StringBuffer();
            int begin=sc.nextInt();
            int end=sc.nextInt();
            for(int i=begin;i<=end;i++)
                sb.append(i);
            str=sb.toString();
            System.out.println(countToken(str, "2"));
        }
        public static int countToken(String str,String token){
            int count=0;
            while(str.indexOf(token)!=-1){
            count++;
            str = str.substring(str.indexOf(token)+token.length());
            }
            return count;
            }
    
    }
    
  • 0
    @ 2015-08-19 21:50:47

    #include<cstdio>
    using namespace std;

    int main()
    {
    int r, l, ans = 0;
    scanf("%d%d", &r, &l);
    for(int i=r; i<=l; i++){
    int bri = i;
    while(bri > 0){
    if(bri%10 == 2)
    ans++;
    bri /= 10;
    }
    }

    printf("%d", ans);
    return 0;
    }
    好水

  • 0
    @ 2015-07-16 11:45:11

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main()
    {
    long long l,r;
    long long s=0;
    cin>>l>>r;
    char a[1000];
    for(int i=l;i<=r;i++)
    {
    a[i]=i;
    while(a[i]>0)
    {
    if(a[i]%10==2)
    ++s;
    a[i]=a[i]/10;
    }
    }
    cout<<s;
    return 0;
    } 哪里错了

  • 0
    @ 2015-06-25 17:04:17

    原来不用string判断也是那么简单...

    Block code

    #include <iostream>
    #include <stdio.h>
    int make2(int v) {
    if (v > 10) {
    int p = v % 10;
    return make2(p) + make2((v - p) / 10);
    }
    if (v == 2)
    return 1;
    return 0;
    }
    int main(int argc, char **argv)
    {
    int L; int R; int val = 0;
    std::cin>>L; std::cin>>R;
    for (;L <= R;L++)
    val += make2(L);
    std::cout<<val;
    return 0;
    }

  • 0
    @ 2015-06-02 16:20:05

    var b: string;
    a,i,j,l,r,tri:longint;
    procedure two(l,r:longint);
    begin
    for i:=l to r do
    begin
    str(i,b);
    for j:=1 to length(b) do
    if b[j]='2' then inc(tri);
    end;
    end;
    begin
    readln(l,r);
    two(l,r);
    write(tri);
    end.

  • 0
    @ 2015-02-04 16:34:35

    #include<stdio.h>
    #include<string.h>
    char ch[100];
    int main()
    {
    int i,l,r,ans=0,x;
    scanf("%d%d",&l,&r);
    for(i=l;i<=r;i++)
    {
    x=i;
    while(x>0)
    {
    if(x%10==2)
    ans++;
    x/=10;
    }
    }
    printf("%d",ans);
    return 0;
    }

  • 0
    @ 2015-01-28 17:49:56

    Pascal Code

    var
    l,r:longint;
    i,n,ans,t:longint;
    begin
    readln(l,r);
    for i:=l to r do
    begin
    t:=i;
    repeat //取出每一位
    n:=t mod 10;
    if n=2 then inc(ans);
    t:=t div 10;
    until t=0;
    end;
    writeln(ans);
    end.

    • @ 2016-08-08 15:12:56

      不错不错!!!,但我的比你**更短!!!**

  • 0
    @ 2015-01-24 20:26:29

    秒过。。。
    大水题。。。
    var l,r,i,ans:integer;
    function num(k:integer):integer;
    var t:byte;
    begin
    num:=0;
    repeat
    t:=k mod 10;
    if t=2 then inc(num);
    k:=k div 10;
    until k=0;
    end;
    begin
    readln(l,r);
    for i:=l to r do
    inc(ans,num(i));
    writeln(ans);
    end.

  • 0
    @ 2014-12-26 17:38:16

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int main()
    {
    int i,l,r,num=0;
    cin>>l>>r;
    for(i=l;i<=r;i++)
    {
    int t,x;
    t=i;
    while (t>0)
    {
    x=t % 10;
    if (x==2)
    num+=1;
    t=t/10;

    }
    }
    cout<<num;
    }

  • 0
    @ 2014-12-20 22:33:23

    略水……不过……

    AC 100 留念

    ###Blockcode

    var
    sum,l,r,i,j,p:longint;
    num:string;
    begin
    sum:=0;
    read(l);
    read(r);
    for i:=l to r do
    begin
    str(i,num);
    p:=pos('2',num);
    while p>0 do
    begin
    inc(sum);
    delete(num,p,1);
    p:=pos('2',num);
    end;
    end;
    write(sum);
    end.

  • 0
    @ 2014-12-02 18:52:11

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    using namespace std;
    main()
    {
    char s[10];
    int a=0,e,i,j,l,r;
    cin>>l>>r;
    for(i=l;i<=r;i++)
    {
    sprintf(s,"%d",i);
    e=strlen(s);
    for(j=0;j<e;j++)
    if(s[j]=='2')
    a++;
    }
    cout<<a;
    }

  • 0
    @ 2014-11-30 14:04:19

    program p1784;
    var sum,l,r,i,j:longint;
    num:string;
    begin
    sum:=0;
    read(l); read(r);
    for i:=l to r do
    begin
    str(i,num);
    for j:=1 to length(num) do
    if num[j]='2' then
    sum:=sum+1;
    end;
    write(sum);
    end.

    简单易懂,自己看吧。如果这题数据规模大点貌似就有点贪心的味道了

  • 0
    @ 2014-11-01 22:53:51

    C++ Code (试试stringstream)

    #include <iostream>
    #include <string>
    #include <sstream>

    using namespace std;

    string str;

    int main(void)
    {
    stringstream ss(str);
    long long ans(0);
    int n(0), m(0);
    cin >> n >> m;
    for (int i = n; i <= m; ++i)
    {
    ss << i;
    }
    ss >> str;
    for (int i = 0; i < str.length(); ++i)
    {
    if (str[i] == '2') { ++ans; }
    }
    cout << ans << endl;
    return 0;
    }

  • 0
    @ 2014-10-03 21:23:57

    C++ Code

    #include<iostream>
    #include<string>
    using namespace std;
    int check(int i);
    int main()
    {
    int start,end,i,count;
    count=0;
    cin>>start>>end;
    for(i=start;i<=end;i++)
    {
    count+=check(i);
    }
    cout<<count;
    return 0;
    }
    int check(int i)
    {
    int temp,count;
    count=0;
    do
    {
    temp=i%10;
    i=i/10;
    if(temp==2) count++;
    }while(i!=0) ;
    return count;
    }

  • 0
    @ 2014-08-16 15:30:38

    var
    l,r:longint;
    i,sum,n:longint;
    begin
    sum:=0;
    read(l,r);
    for i:=l to r do
    begin
    n:=i;
    while n<>0 do
    begin
    if n mod 10=2 then sum:=sum+1;
    n:=n div 10;
    end;
    end;
    writeln(sum);
    end.

信息

ID
1784
难度
2
分类
模拟 点击显示
标签
递交数
2761
已通过
1662
通过率
60%
被复制
19
上传者