string - Wrong answer in c++ -


You have been given a DNA sequence, and some enzymes, a DNA sequence is like this: ATGCTGCTATGCATGCAGTGACT , and you are given an enzyme that can remove the AT and GC sequences. In this way, you must first remove all the events of AT from DNA and then improve DNA and apply the next enzyme to remove all GC incidents. The problem will be the issue string, which you get to improve the fragments extracted by the previous enzyme.

Input

The first line input contains an integer N, which represents the number of enzymes. DNA sequence in the first line is the input B1, B2, B3 ... BN in the next T lines.

Output

The sequence for given input DNA, the last improved DNA in which single bar B1, B2, B3 ... BN . From the removal of all incidents, a single line is produced.

If DNA is completely eaten then print 0 indicates there is no DNA balance.

  Obligations 1 & lt; = N & lt; Example: 1:   

Input:

  2 ATACGCATGACGATGCATGCAGCAT ATA GC   

Output:

  CATGACGATATAAT   

Example 2: Input:

  3 ATGCATGCATCGACTCAGCATCAGCATCGACTA TG GC AT   

Output:

  ACACCGACTCACACGACTA   

My code:

I tried to use the string in C ++, I found:

The term 'std :: out_of_range' is terminated after throwing an example (): basic_string :: Erase ()

  #include & lt; Iostream & gt; # Include & lt; Stdio.h & gt; # Include & lt; Algorithm & gt; # Include & lt; Math.h> #include & lt; Vector & gt; # Include & lt; Set & gt; # Include & lt; Stdlib.h & gt; #include & lt; String.h & gt; #include & lt; Queue & gt; #include & lt; Stack & gt; # Include & lt; Assert.h & gt; # Include & lt; Limits.h & gt; using namespace std; Int main () {string str, str1; Int n; scanf ("% d", & amp; n); Cin & gt; & Gt; Str; While (n--) {cin> & Gt; Str1; Int len ​​= str1.length (); Int len1 = str.length (); {Int found = str.find (str1) for (int i = 0; i & lt; len1; i ++); Str.erase (found, found + lane); }} Cout & lt; & Lt; Str; Return 0; }    

Three main problems:

Number one, out of Limit Exceptions on String :: Errors.
Test has been determined that a value has actually been returned:

  if (found! = Std :: string :: npos)   

Number two, searching correctly detected (also fixed by keeping track of a size_t not a int ) And search from the next location:

  found = str.find (found str1,);   

Number three, using string :: erase properly. Fixing by using the length substring of not length> position : str.erase (found, lane);

I still have not added any input validation for your code.

()

  #include & lt; String & gt; # Include & lt; Iostream & gt; Int main () {std :: string str; Std :: string str1; Int n; Std :: CIN & gt; & Gt; N; Std :: CIN & gt; & Gt; Str; While (n--) {std :: cin & gt; & Gt; Str1; Int len ​​= str1.length (); Size_t found = 0; For (unsigned int i = 0; i & lt; str.length (); i + +) {found = str.find (str1, found); If (found! = Std :: string :: npos) {str.erase (found, lane); } And {break} }}} Std :: cout & lt; & Lt; (Str.length (?) Str: "0"); Return 0; }   

Idone output for each example input (I've added your example output between / * * / ):

  Success time: 0 Memory: 3476 Signal: 0 CatGagatat / * CatGadgetatt * * / Success Time: 0 Memory: 3476 Signal: 0 ACA CAGCCTCACACACACACATA / ACAACAGACCCTCACACACACAA /    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -