piKapi2603's blog

By piKapi2603, history, 2 years ago, In English

Please help me understand the issue here. When I run my code on codeblocks(V20.03) it gives me output as intended. But when I submit my code on CF or ideone, it shows me wrong answer or does not give the output as intended. Here is the problem statement and also the code that I submitted:

problem statement: 151B - Phone Numbers

my submission: 145356990

It is a long code as I still write code like a noob. So, sorry for that. Please help me understand the main issue here. It will be really helpful. ===TIA===

  • Vote: I like it
  • -1
  • Vote: I do not like it

»
2 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

At first, you input an long long int value as an usual int. In function process you write sscanf((s+"*1").c_str(), "%2d-%2d-%2d*%d", &a, &b, &c, &d); but a,b,c,d are long long int and you need to input them not as "%d" but as %Ld. So, at first ,you must replace your input for sscanf((s+"*1").c_str(), "%2Ld-%2Ld-%2Ld*%Ld", &a, &b, &c, &d); But if you will do this, your code will still work incorrect. This is because there are such words in a problem description — "Print the names in the order in which they are given in the input data". You don't do it, because you store names in a std::map, but std::map has its oneself order of an elements that stored in it, and don't keep an initial order of the names. You must fix it too if you want your code to work correct.