1 solutions

  • 0
    @ 2025-11-5 16:40:48

    C++ :

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

    Pascal :

    var
      l,r:1..10000;
      i,j,h,c:longint;
      s:string;
    begin
      {assign(input,'two.in');
      assign(output,'two.out');
      reset(input);
      rewrite(output);}
      readln(l,r);
      c:=0;
      for i:=l to r do
        begin
          str(i,s);
          h:=length(s);
          for j:=1 to h do
            if s[j]='2'
              then c:=c+1;
        end;
      writeln(c);
     { close(input);
      close(output);}
    end.
    
    • 1

    Information

    ID
    17928
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By