0

I am getting SIGCONT error while running the code in codechef ide whereas on my local ide the same code runs fine.
The problem code is "TYPING" and it is from Snackdown Practice Contest: Beginner.

The code is below:

#include <iostream>
#include <iterator>
#include <map>
#include <string>
typedef long long ll;


ll FindCount(const char* str,ll num){
     
     char previous =str[0];
     ll individual_count=2;
     
     for(ll i =1 ;i<num;i++){
          
          if(previous=='d'||previous=='f'){
               
               if(str[i]=='d'||str[i]=='f'){
                    individual_count+=4;
               }
               else{
                    individual_count+=2;
               }
          }
          
          else{
               
               if(str[i]=='j'||str[i]=='k'){
                    individual_count+=4;
               }
               else{
                    individual_count+=2;
               }
          }
          previous=str[i];
     }

     return individual_count;
}

int main()
{

     ll t;
     std::cin>>t;

    while(t--)
    {

         std::map<std::string,ll> m;
         ll count=0;
         ll n=0;
         std::cin>>n;
         
         while(n--){
              
              std::string str;
              std::cin>>str;
              std::map<std::string,ll>::iterator itr;
              itr=m.find(str);
              
              if(itr!=m.end()){
                   count+=(itr->second)/2;
              }
              
              else{
                   ll num = str.size();
                   ll temp = FindCount(str.c_str(),num);
                   count+=temp;
                   m.insert({str,temp});
              }
         }
         
         std::cout<<count<<"\n";
    }
    return 0;
}

The link to the problem statement is: https://www.codechef.com/SDPCB21/problems/TYPING

I am getting an infinite number of '0' as output each on new line.

Please tell me if there is any logical error or error of any kind in the code.

Thankyou.

  • Hard to find a logic error if we don't know what the code is supposed to be doing. P.S. [Why should I not #include ??](https://stackoverflow.com/q/31816095) – 001 Sep 13 '21 at 14:13
  • @JohnnyMopp ok I will try to explain it in the question itself – Dishant Singh Sep 13 '21 at 14:15
  • 1
    While using stuff like `#define ll long long` may reduce the amount of typing you need to do, and may win points in some bizarre coding competitions, such practices make code very hard to read, very hard to debug, and will likely disincline people on Stack Overflow from trying to help you. Please learn to write *good* code, with good, clear, easy-to-read variable names. – Adrian Mole Sep 13 '21 at 14:16
  • It accepts if you remove the whole "#ifndef ONLINE_JUDGE...#endif" part I don't know why is that there nor why it causes error – Botond Horváth Sep 13 '21 at 15:02
  • @BotondHorváth If `ONLINE_JUDGE` is not defined the code redirects `stdin` to that file. If that file doesn't exist then `t` and `n` are not initialized and may have some very large random values. In that case `cout< – 001 Sep 13 '21 at 15:06
  • @JohnnyMopp problem statement is big so I couldn't explain it here, instead, I have provided the link to the problem statement in the question, please have a look at it – Dishant Singh Sep 13 '21 at 15:52
  • @BotondHorváth yes i did remove the #ifndef part but the same error is still there – Dishant Singh Sep 13 '21 at 15:53
  • 1
    It must be something with the way you read in `t` or `n`. Just for fun, I typed up a solution. It is similar to yours but does error checking. If you want to see it: https://onlinegdb.com/Oeh9VPuJ1 – 001 Sep 13 '21 at 17:05
  • @JohnnyMopp Yes, I just added "if(std::cin>>)" block before taking both 't' and 'n' input and kept rest of the code same and it worked!! There was indeed something wrong with the way I was taking the 't' and 'n' input. Thanks for your help. – Dishant Singh Sep 13 '21 at 19:03

0 Answers0