Guest User

Untitled

a guest
Mar 15th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. bool ifStringMatchS(string test, string S, int cutBegin) {
  8.     return !test.compare(S.substr(cutBegin, test.size()));
  9. }
  10.  
  11. void solve(vector<string> L, string S) {
  12.     vector<int> ifPossibleArray(S.size(), 0);
  13.     for (int i = 0; i < S.size(); i++) {
  14.         if (i == 0 || ifPossibleArray[i - 1]) {
  15.             for (int j = 0; j < L.size(); j++) {
  16.                 if ((i + L[j].size() - 1 < S.size()) && ifPossibleArray[i + L[j].size() - 1] == 0) {
  17.                     if (ifStringMatchS(L[j], S, i)) {
  18.                         ifPossibleArray[i + L[j].size() - 1] = 1;
  19.                     }
  20.                 }
  21.             }
  22.         }
  23.     }
  24.     cout << ifPossibleArray[S.size() - 1];
  25. }
  26.  
  27. int main() {
  28.     string S = "abcdefghjijklmnopqrstuz";
  29.     vector<string> L{
  30.         "a",
  31.         "ab",
  32.         "abc",
  33.         "abcd",
  34.         "abcde",
  35.         "abcdef",
  36.         "abcdefg",
  37.         "abcdefgh",
  38.         "abcdefghj",
  39.         "abcdefghji",
  40.         "abcdefghjij",
  41.         "abcdefghjijk",
  42.         "abcdefghjijkl",
  43.         "abcdefghjijklm",
  44.         "abcdefghjijklmn",
  45.         "abcdefghjijklmno",
  46.         "abcdefghjijklmnop",
  47.         "abcdefghjijklmnopq",
  48.         "abcdefghjijklmnopqr",
  49.         "abcdefghjijklmnopqrs",
  50.         "abcdefghjijklmnopqrst",
  51.         "abcdefghjijklmnopqrstu",
  52.         "b",
  53.         "bc",
  54.         "bcd",
  55.         "bcde",
  56.         "bcdef",
  57.         "bcdefg",
  58.         "bcdefgh",
  59.         "bcdefghj",
  60.         "bcdefghji",
  61.         "bcdefghjij",
  62.         "bcdefghjijk",
  63.         "bcdefghjijkl",
  64.         "bcdefghjijklm",
  65.         "bcdefghjijklmn",
  66.         "bcdefghjijklmno",
  67.         "bcdefghjijklmnop",
  68.         "bcdefghjijklmnopq",
  69.         "bcdefghjijklmnopqr",
  70.         "bcdefghjijklmnopqrs",
  71.         "bcdefghjijklmnopqrst",
  72.         "bcdefghjijklmnopqrstu",
  73.         "c",
  74.         "cd",
  75.         "cde",
  76.         "cdef",
  77.         "cdefg",
  78.         "cdefgh",
  79.         "cdefghj",
  80.         "cdefghji",
  81.         "cdefghjij",
  82.         "cdefghjijk",
  83.         "cdefghjijkl",
  84.         "cdefghjijklm",
  85.         "cdefghjijklmn",
  86.         "cdefghjijklmno",
  87.         "cdefghjijklmnop",
  88.         "cdefghjijklmnopq",
  89.         "cdefghjijklmnopqr",
  90.         "cdefghjijklmnopqrs",
  91.         "cdefghjijklmnopqrst",
  92.         "cdefghjijklmnopqrstu",
  93.         "d",
  94.         "de",
  95.         "def",
  96.         "defg",
  97.         "defgh",
  98.         "defghj",
  99.         "defghji",
  100.         "defghjij",
  101.         "defghjijk",
  102.         "defghjijkl",
  103.         "defghjijklm",
  104.         "defghjijklmn",
  105.         "defghjijklmno",
  106.         "defghjijklmnop",
  107.         "defghjijklmnopq",
  108.         "defghjijklmnopqr",
  109.         "defghjijklmnopqrs",
  110.         "defghjijklmnopqrst",
  111.         "defghjijklmnopqrstu",
  112.         "e",
  113.         "ef",
  114.         "efg",
  115.         "efgh",
  116.         "efghj",
  117.         "efghji",
  118.         "efghjij",
  119.         "efghjijk",
  120.         "efghjijkl",
  121.         "efghjijklm",
  122.         "efghjijklmn",
  123.         "efghjijklmno",
  124.         "efghjijklmnop",
  125.         "efghjijklmnopq",
  126.         "efghjijklmnopqr",
  127.         "efghjijklmnopqrs",
  128.         "efghjijklmnopqrst",
  129.         "efghjijklmnopqrstu",
  130.         "f",
  131.         "fg",
  132.         "fgh",
  133.         "fghj",
  134.         "fghji",
  135.         "fghjij",
  136.         "fghjijk",
  137.         "fghjijkl",
  138.         "fghjijklm",
  139.         "fghjijklmn",
  140.         "fghjijklmno",
  141.         "fghjijklmnop",
  142.         "fghjijklmnopq",
  143.         "fghjijklmnopqr",
  144.         "fghjijklmnopqrs",
  145.         "fghjijklmnopqrst",
  146.         "fghjijklmnopqrstu",
  147.         "g",
  148.         "gh",
  149.         "ghj",
  150.         "ghji",
  151.         "ghjij",
  152.         "ghjijk",
  153.         "ghjijkl",
  154.         "ghjijklm",
  155.         "ghjijklmn",
  156.         "ghjijklmno",
  157.         "ghjijklmnop",
  158.         "ghjijklmnopq",
  159.         "ghjijklmnopqr",
  160.         "ghjijklmnopqrs",
  161.         "ghjijklmnopqrst",
  162.         "ghjijklmnopqrstu",
  163.         "h",
  164.         "hj",
  165.         "hji",
  166.         "hjij",
  167.         "hjijk",
  168.         "hjijkl",
  169.         "hjijklm",
  170.         "hjijklmn",
  171.         "hjijklmno",
  172.         "hjijklmnop",
  173.         "hjijklmnopq",
  174.         "hjijklmnopqr",
  175.         "hjijklmnopqrs",
  176.         "hjijklmnopqrst",
  177.         "hjijklmnopqrstu",
  178.         "j",
  179.         "ji",
  180.         "jij",
  181.         "jijk",
  182.         "jijkl",
  183.         "jijklm",
  184.         "jijklmn",
  185.         "jijklmno",
  186.         "jijklmnop",
  187.         "jijklmnopq",
  188.         "jijklmnopqr",
  189.         "jijklmnopqrs",
  190.         "jijklmnopqrst",
  191.         "jijklmnopqrstu",
  192.         "i",
  193.         "ij",
  194.         "ijk",
  195.         "ijkl",
  196.         "ijklm",
  197.         "ijklmn",
  198.         "ijklmno",
  199.         "ijklmnop",
  200.         "ijklmnopq",
  201.         "ijklmnopqr",
  202.         "ijklmnopqrs",
  203.         "ijklmnopqrst",
  204.         "ijklmnopqrstu",
  205.         "j",
  206.         "jk",
  207.         "jkl",
  208.         "jklm",
  209.         "jklmn",
  210.         "jklmno",
  211.         "jklmnop",
  212.         "jklmnopq",
  213.         "jklmnopqr",
  214.         "jklmnopqrs",
  215.         "jklmnopqrst",
  216.         "jklmnopqrstu",
  217.         "k",
  218.         "kl",
  219.         "klm",
  220.         "klmn",
  221.         "klmno",
  222.         "klmnop",
  223.         "klmnopq",
  224.         "klmnopqr",
  225.         "klmnopqrs",
  226.         "klmnopqrst",
  227.         "klmnopqrstu",
  228.         "l",
  229.         "lm",
  230.         "lmn",
  231.         "lmno",
  232.         "lmnop",
  233.         "lmnopq",
  234.         "lmnopqr",
  235.         "lmnopqrs",
  236.         "lmnopqrst",
  237.         "lmnopqrstu",
  238.         "m",
  239.         "mn",
  240.         "mno",
  241.         "mnop",
  242.         "mnopq",
  243.         "mnopqr",
  244.         "mnopqrs",
  245.         "mnopqrst",
  246.         "mnopqrstu",
  247.         "n",
  248.         "no",
  249.         "nop",
  250.         "nopq",
  251.         "nopqr",
  252.         "nopqrs",
  253.         "nopqrst",
  254.         "nopqrstu",
  255.         "o",
  256.         "op",
  257.         "opq",
  258.         "opqr",
  259.         "opqrs",
  260.         "opqrst",
  261.         "opqrstu",
  262.         "p",
  263.         "pq",
  264.         "pqr",
  265.         "pqrs",
  266.         "pqrst",
  267.         "pqrstu",
  268.         "q",
  269.         "qr",
  270.         "qrs",
  271.         "qrst",
  272.         "qrstu",
  273.         "r",
  274.         "rs",
  275.         "rst",
  276.         "rstu",
  277.         "s",
  278.         "st",
  279.         "stu",
  280.         "t",
  281.         "tu",
  282.         "u",
  283.     };
  284.     solve(L, S);
  285.     return 0;
  286. }
Advertisement
Add Comment
Please, Sign In to add comment