Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Himanshu is a very strange person, so every day he has a new stunning number. But since it's only one, in case he needs multiple numbers, Himanshu came up with the definition of "Suffix stunning number".
A number is called a Suffix stunning number if it ends with Himanshu's stunning number.
So for example, if Himanshu's stunning number is 25, then Suffix stunning number would be 625,11225, and 25, whereas 5 and 2255, are not.
Write a program for Himanshu that will report how many Suffix stunning numbers are available not exceeding M
Input format
The only line of the input file contains two integers N and M, where N is Himanshu's stunning number.
Output format
Print the count of Suffix stunning numbers not exceeding M.
Constraints
1<=N<=M<=2∗
Input
5 15

Output
2

Explanation
N ​=5
Suffix stunning numbers less then M=15 are 5 and 15
the code i

What I have tried:

i have tried a code given below but it does not pass test cases
C++
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
  //write your code here
long int N,M,cnt=0,cmt=0;
  cin>>N>>M;
  if(N>M)
  cout<<0;
  else
  {
  while(N>0)
  {
      cmt++;
      N/=10;
  }
 long int x=pow(10,cmt);
  for( long int i=0;i<=M;i++)
  {
    if(i%x==N)
    cnt++;
  }
  cout<<cnt;
  }

  return 0;
}
Posted
Updated 22-Aug-20 7:32am
v2

And we have no idea what your test cases are!

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
First of all, when you want help for a challenge from a challenge site, it is a good idea to post a link yo original page. Because every word matters.
Your questions here says: 1<=N<=M<=2∗
But on stackoverflow, it says: 1<=N<=M<=2∗109
Which one is correct or both wrong ?
Quote:
i have tried a code given below but it does not pass test cases

The sample test in question is OK, show test that fail.
Do not expect any of us experimenting until we find a failing input, it is a real job.

Without more details, the only way to go is using the debugger with failing input to see when it go wrong.
Quote:
How do I develop different logic for the code given below

Compare your own logic with a sheet of paper and a pencil with the logic of your code. You may get a surprise.
-----
Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
v4
Best is to structure your code at first by using functions or classes, because it helps to test your code.

Your logic for getting Himanshu number is wrong. The first number in N but ALL following numbers are calculated by the distance to the next number.

example: 5 next is 15, so distance is 10 => 25, 35

I leave it to you to calculate that difference and hammer out the details ;-)
 
Share this answer
 
Comments
Patrice T 22-Aug-20 16:46pm    
Looks like OP is too busy to answer questions or investigate hints given. He have time only for a full blowup solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900