a53

repetare

a53
Sep 17th, 2017 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("repetare.in");
  4. ofstream fout("repetare.out");
  5. int n , m , a[1005], b[1005];
  6.  
  7. int main()
  8. {
  9. fin >> n;
  10. for(int i = 1 ; i <= n ; i ++)
  11. fin >> a[i];
  12. fin >> m;
  13. for(int i = 1 ; i <= m ; ++ i)
  14. fin >> b[i];
  15. int cnt = 1;
  16. bool ok = true;
  17. int i = 1 , j = 1;
  18. while(j <= m && ok)
  19. {
  20. int ivechi = i;
  21. bool marit = false;
  22. while(i <= n && a[i] != b[j])
  23. i ++;
  24. if(i == n + 1)
  25. {
  26. i = 1;
  27. cnt ++;
  28. marit = true;
  29. while(i < ivechi && a[i] != b[j])
  30. i ++;
  31. }
  32.  
  33. if(i == ivechi && marit)
  34. {
  35. // nu l-am gasi pe b[j] in a[], nu se poate
  36. ok = false;
  37. }
  38. else
  39. i ++, j ++;
  40. }
  41. if(ok)
  42. fout << cnt;
  43. else
  44. fout << "IMPOSIBIL";
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment