In: Computer Science
Use C++ to write a program that reads in a binary string from the command line and applies the following (00, 1101) tag-system: if the first bit is 0, deletes the first three bits and append 00; if the first bit is 1, delete the first three bits and append 1101. Repeat as long as the string has at least 3 bits. Try to determine whether the following inputs will halt or go into an infinite loop: 10010, 100100100100100100. Use a queue.
//C ++ program
#include<bits/stdc++.h>
using namespace std;
int main(){
   queue <char > Q;
   string str;
  
   cout<<"Enter string : ";
   cin>>str;
   for(int i=0;i<str.length();i++){
       Q.push(str[i]);
   }
  
   while(Q.size()>=3){
       cout<<"Loop\n";
       if(Q.front()=='0'){
          
Q.push('0');
          
Q.push('0');
       }
       else if(Q.front()=='1'){
          
Q.push('1');
          
Q.push('1');
          
Q.push('0');
          
Q.push('1');
       }
       Q.pop();
       Q.pop();
       Q.pop();
      
   }
  
   cout<<"\nHalt";
   return 0;
}