jeudi 3 décembre 2020

Runtime Error: Runtime ErrorSegmentation Fault (SIGSEGV)

LINK TO THE ACTUALL PROBLEM I am trying to solve a question on codechef but getting a runtime error. Although when i executed same code on virtual studio code, no error was observed.

#include<bits/stdc++.h>
    using namespace std; 
   int main()
  {
    int t;
     cin>>t;
    while(t--)
    {ios_base::sync_with_stdio(false);
    cin.tie(NULL);
       
        int n;
        cin>>n;
        string s[n],b;
        int i=0;
        while(i<n)
        {
            i++;
            cin>>s[i];
            if(i==0) b=s[0];
            else {
                if(b.length()<=s[i].length()) b=s[i];
                }
            
        }
        cout<<b;
    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire