jeudi 29 mars 2018

Missing lines of output on a hackereath code

I was solving a question on hackerearth. The question is to replace every alphabet with another alphabet which is the nearest prime of the former alphabet. (Magical word question on hackerearth)

I tried solving the question, the code failed to pass some testcases. When I tried debugging the code after some iterations at cin, the debugging thread was going to waiting state.

For the following input:
10
229 uTkxYwOdZlyzGtVUSYqZhjWnEFazKOOTDuWoNLRqinqmpSDfZHdcREUjYFiGEksppnDHzrHOBtsXSBWOczVRTxlxdVjDgoJUMEfTUmzpWOrXnuMHRIiqFhDFEJMLzUtOsfQQhhXmJbHgyHHbcWOQPEgnQxPmHTtNmiqhkZMvgdRWnYrReBlIPvjQPPLyGUNSGfiICKTBtnwHeccGjdBqLqRtOXJUiHRaFPyce
322 bGxPVNuxkZQKIHbIZVWZpmBpshkDaIosjZHtbMfHrmsHitrrGOmXENIhkuFklSFhvlacrdnmqkVRTYuWnsPzdTBEeDHpUmoKfwmyUrgINuCWgIAZLZkChbKkJZIRMxZFoZLiwRqQKvDzbJXMfikuSOlpUwtdvXpjljUmzmroCCkwdQRUgcOYKgNAxwoBLrUPtvOnaBpypIDManeMydmoOgTJILdveEqNwtQxioVoTqHxSBSEJUJpnNKlCcwhnTUoKOZYphJTWjQSqTXqbGNSZYNpdgdkotTGPacLkzwLJGwVsJJmSpBdvgfMOWXlLxTLur
365 eMzcThGLZavSoaxOJLwHMBlRqffCOygUiCnrDFRSSzAimJjqZlbMnHlYIKExtEzQicrxZjezPCNIBmoSMdSgnfLmqurpJFbqZQxksUUnicPBVJKOBegWzlkpsWfqUwWXlaxVjOvLdOTlLXmAjZVfvuzgfxxWaoqqkkEpUrBymEYGhNxSGMXYoguRSgqLRVOexuVNzlnFvLZMUITJTkRhLwQFChXzjsiuorcTQiunGursbgAaqdlDoqSZaXgRwNNtMXhdHhqBZGLlfjwcjaBVvGzxiIzIixwXLmgHtTkIHshjBgOMudQjFeldITmjlusbwjhaMxsrZNoSiyVxBpNBUHcENBdfXNOHUiohXoUvfTRuj
388 WUfLfyyXS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owPaoByolyzPCMrMhLONuMXxQQYiAVZnyWtwHiuMVXQaGIKnzpoCtCUwDIWRTTVHtXlhHVVZqgXOzjdkbKuomBqBMfewXdAkWjyYXWOtgDaFvhbzsHZfldetSpreQcCHDVtaZyNnZVUyDppjoipVVEFExTHcBQoXrQLYVaCcAZDAVFnOyhgqUftjLMT

My code :

#include<iostream>
#include<vector>

using namespace std;
vector<int> prime;

void seive(){
   vector<int> ascii(257,true);
   ascii[0]=false;ascii[1]=false;
   for(int index = 2 ;index < 257 ; index++){
       if(ascii.at(index)){
          if((index>=65 && index<=90) || (index>=97 && index<=122))
             prime.push_back(index);
          for(int num=1;num*index < 257;num++){
             ascii[num*index]=false;
          }
        }
    }
 }
 int binary_search(int low,int high,int key){
     if(low<=high){
         int mid=(low+high)/2;
         if(mid==0){
             if(key-prime.at(mid) == prime.at(mid+1)-key)
                 return prime.at(mid);
             if(key-prime.at(mid) < prime.at(mid+1)-key)
                 return prime.at(mid);
             else
                 return prime.at(mid+1);
      }
      if(prime[mid]==key)
          return prime.at(mid-1);
      if(prime.at(mid)<key && prime.at(mid+1)>key){
          if(key-prime.at(mid) == prime.at(mid+1)-key)
              return prime.at(mid);
           if(key-prime.at(mid) < prime.at(mid+1)-key)
               return prime.at(mid);
            else
               return prime.at(mid+1);
       }
       if(key<prime.at(mid))
            return binary_search(low,mid-1,key);
       else
            return binary_search(mid+1,high,key);
   }
   return 0;
}

int main(void){
   ios_base::sync_with_stdio(false);
   //cin.tie(NULL);
   int testcases;
   seive();
   cin>>testcases;
   for(int test=0;test<testcases;test++){
       int length;
       cin>>length;
       char str[length];
       memset(str,'\0',length);
       cin>>str;
       for(int index=0;str[index]!='\0';index++){
           int ascii_value=str[index];
           if(find(prime.begin(),prime.end(),ascii_value)!=prime.end()) 
               continue;
           if(ascii_value >= 113){
             str[index]=113;
             continue;
           }
           int nearest_prime = 
                   binary_search(0(int)prime.size()-1,ascii_value);
           str[index]=nearest_prime;
      }
      cout<<str<<endl<<endl;
  }
  return 0;
}

Is there a way to understand why thread is going to waiting state.When I saw my output file on hackerearth it shows few lines in my output are not present.

The output should be as below

qSkqYqOeYkqqGqSSSYqYgkYmCGaqIOOSCqYmOISqgmqmqSCeYGeaSCSkYGgGCkqqqmCGqqGOCqqYSCYOaqSSSqkqeSkCgmISOCeSSmqqYOqYmqOGSIgqGgCGCIOIqSqOqeOOggYmIaGgqGGaaYOOOCgmOqOmGSqOmgqgkYOqgeSYmYqSeCkIOqkOOOIqGSOSGegICISCqmqGeaaGkeCqIqSqOYISgGSaGOqae aGqOSOqqkYOIIGaIYSYYqmCqqgkCaImqkYGqaOeGqmqGgqqqGOmYCOIgkqGkkSGgqkaaqemmqkSSSYqYmqOqeSCCeCGqSmmIeqmqSqgIOqCYgICYIYkCgaIkIYISOqYGmYIgqSqOIqCqaIYOegkqSOkqSqqeqYqkkkSmqmqmCCkqeOSSgaOYIgOCqqmCIqSOqqOmaCqqqICOameOqemmOgSIIIeqeCqOqqOqgmSmSqGqSCSCISIqmOIkCaqgmSSmIOYYqgISYkOSqSYqaGOSYYOqegekmqSGOaaIkqqIIGqSqIImSqCeqgeOOYYkIqSIqq eOqaSgGIYaqSmaqOIIqGOCkSqeeCOqgSgCmqCGSSSqCgmIkqYkaOmGkYIICqqCqOgaqqYkeqOCOICmmSOeSgmeImqqqqIGaqYOqkqSSmgaOCSIIOCegYqkkqqYeqSqYYkaqSkOqIeOSkIYmCkYSeqqqgeqqYamqqkkCqSqCqmCYGgOqSGOYYmgqSSgqISSOeqqSOqkmGqIYOSISISkSgIqOGCgYqkqgqmqaSOgqmGqqqagCaqekCmqSYaYgSqOOqOYgeGgqCYGIkekqakaCSqGqqgIqIgqqYImgGqSkIGqgkCgOOqeOkGekeISmkkqqaqkgaOqqqYOmSgqSqCqOCSGaCOCeeYOOGSgmgYmSqeSSqk YSeIeqqYSIqgqaIOaOYqCqYmCOqqCqkCqqeqmeGqOqeqmaqaSOqGmkSmOqYOgGIaOgIYaISCgkGGaOOCggqq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