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 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. Input: Output: Example 2: Input: Output: 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 () Three main problems: Number one, out of Limit Exceptions on Number two, searching correctly Number three, using I still have not added any input validation for your code. () Idone output for each example input (I've added your example output between B1, B2, B3 ... BN in the next T lines.
Obligations 1 & lt; = N & lt; Example: 1:
2 ATACGCATGACGATGCATGCAGCAT ATA GC
CATGACGATATAAT
3 ATGCATGCATCGACTCAGCATCAGCATCGACTA TG GC AT
ACACCGACTCACACGACTA
#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; }
String :: Errors.
Test has been determined that a value has actually been returned:
if (found! = Std :: string :: npos)
detected (also fixed by keeping track of a
size_t not a
int ) And search from the next location:
found = str.find (found str1,);
string :: erase properly. Fixing by using the length substring of
str.erase (found, lane);
#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; }
/ *
* / ):
Success time: 0 Memory: 3476 Signal: 0 CatGagatat / * CatGadgetatt * * / Success Time: 0 Memory: 3476 Signal: 0 ACA CAGCCTCACACACACACATA / ACAACAGACCCTCACACACACAA /
Comments
Post a Comment