Advertisement
howarto

Solución ej. 1 examen final 20 juny 2011

Dec 22nd, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int pos(const string& a, const string& b) {
  6.     int n = a.size();
  7.     int m = b.size();
  8.     if (m < n) return -1;
  9.  
  10.     for (int i = 0; i < (m - n); ++i) {
  11.         bool salta = false;
  12.         int j = 0;
  13.         while (j < n and not salta) {
  14.             if (a[j] != '?' and a[j] != b[i + j]) salta = true;
  15.             ++j;
  16.         }
  17.         if (not salta) return i;
  18.     }
  19.     return -1;
  20. }
  21.  
  22. int main(){
  23.     int n;
  24.     string x = "A?TC";
  25.     string y = "AGGGTCATCAATCGTC";
  26.     while (cin >> n) {
  27.         cout << pos(x, y) << endl;
  28.  
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement