Advertisement
Fahim_7861

BIC 5.1

Dec 19th, 2020
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5. typedef pair<ll,ll>pll;
  6. typedef pair<ll,pair<ll,ll>>plll;
  7. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  8. #define vll(v) v.begin(),v.end()
  9. #define all(x) x.rbegin(),x.rend()
  10. #define min3(a, b, c) min(a, min(b, c))
  11. #define max3(a, b, c) max(a, max(b, c))
  12. #define F first
  13. #define S second
  14. #define in freopen("input.txt", "r", stdin)
  15. #define out freopen("output.txt", "w", stdout)
  16. #define minheap int,vector<int>,greater<int>
  17. #define pb push_back
  18. #define eb emplace_back
  19. #define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
  20. #define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
  21. #define bug cout<<"BUG"<<endl;
  22. const int Max = 2e5 + 10;
  23. const int Mod = 1e9 + 7;
  24. const double PI =3.141592653589793238463;
  25. bool compare(const string &a, const string &b)
  26. {
  27. for(ll i=0; i<a.size(); i++)
  28. {
  29. if(a[i]!=b[i] && (a[i]=='$' || b[i]=='$'))
  30. {
  31.  
  32. if(a[i]=='$')return 1;
  33.  
  34. else if(b[i]=='$')return 0;
  35. }
  36.  
  37. else if(a[i]<b[i])return 1;
  38.  
  39. else if(a[i]>b[i])return 0;
  40. }
  41.  
  42. return 1;
  43. }
  44. ll lcm(ll a,ll b)
  45. {
  46. if(a==0 || b==0)return 0;
  47.  
  48. return a/__gcd(a,b)*b;
  49. }
  50.  
  51. void input(ll ara[],ll n)
  52. {
  53. for(ll i=0; i<n; i++)cin>>ara[i];
  54. }
  55. void print(ll ara[],ll n)
  56. {
  57. for(ll i=0; i<n; i++)
  58. cout<<ara[i]<<" ";
  59. cout<<endl;
  60. }
  61.  
  62.  
  63.  
  64. void printCycleRotation(vector<string>cyclicRotation)
  65. {
  66.  
  67. for(auto x : cyclicRotation)
  68. cout<<x<<endl;
  69. }
  70.  
  71. string BwtGenome(vector<string>cyclicRotation)
  72. {
  73. string ans;
  74. for(auto x : cyclicRotation)
  75. ans+=x.back();
  76.  
  77. return ans;
  78. }
  79.  
  80. void RleString(string bwtGenome)
  81. {
  82. cout<<"RLE(BWT((Genome)) : ";
  83. ll i=0,n=bwtGenome.size();
  84. while(i<n)
  85. {
  86. ll now=i;
  87.  
  88. while(i<n && bwtGenome[now]==bwtGenome[i])
  89. i++;
  90.  
  91. cout<<bwtGenome[now]<<i-now;
  92.  
  93.  
  94. }
  95.  
  96. cout<<endl;
  97. }
  98. int main()
  99. {
  100.  
  101. fastread();
  102.  
  103. ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;
  104.  
  105. bool flag=false;
  106.  
  107.  
  108.  
  109. string genome;
  110.  
  111. cout<<"input the genome"<<endl;
  112.  
  113. cin>>genome;
  114.  
  115. string temp=genome;
  116.  
  117. n=genome.size();
  118.  
  119.  
  120.  
  121. if(temp[n-1]!='$')
  122. {
  123. temp+='$';
  124.  
  125. n++;
  126. }
  127.  
  128.  
  129.  
  130.  
  131. vector<string>cyclicRotation;
  132.  
  133. cout<<"\nAll cyclic Rotation of "<<temp<<endl<<endl;
  134.  
  135. cyclicRotation.eb(temp);
  136.  
  137. while(temp[n-2]!='$')
  138. {
  139. temp=temp[n-1]+temp;
  140. temp.pop_back();
  141.  
  142. cyclicRotation.eb(temp);
  143. }
  144.  
  145.  
  146. printCycleRotation(cyclicRotation);
  147.  
  148.  
  149. cout<<"\nSort The lexiographically \n"<<endl;
  150.  
  151. sort(cyclicRotation.begin(),cyclicRotation.end(),compare);
  152.  
  153. printCycleRotation(cyclicRotation);
  154.  
  155. string BWTGENOME=BwtGenome(cyclicRotation);
  156.  
  157. cout<<"BWT(Genome) is : "<<BWTGENOME<<endl;
  158.  
  159.  
  160.  
  161.  
  162. RleString(BWTGENOME);
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172. }
  173.  
  174.  
  175. //GCAGGGTGCA
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement