/*
Alec Mikell
2/7/13
Potter
Contest #2
Enloe
Junior 5
*/
#include
<iostream>
#include
<string>
using namespace
std;
void cell(){
string
op;//String for the operator, first line of input.
string
acslcell;//String for the physical string of 8-bits.
cin>>op;//cin
the operator.
cin>>acslcell;//cin
the cell.
//Note to self,
strings start at 0.
string opcheck1 =
op.substr(0,3);
string opcheck2 =
op.substr(0,8);
if(op ==
"divide"){//Divide the 8-bit string.
string f;//First
8-bit string.
string
f2;//Second 8-bit string.
f =
acslcell.substr(0,4);//Take the first 4 letters.
f2 =
acslcell.substr(4,4);//Take the second 4 letters.
string a;//First
answer.
string
a2;//Second answer.
a = f +
f;//Combine!
a2 = f2 + f2;//Combine!
cout<<a<<",
"<<a2<<endl;//cout the answer.
}else if(opcheck1
== "add"){//Add the 8-bit string.
string num =
op.erase(0,3);//Eliminate the add from the string.
char addchar =
num[0];//Take that remaining character from the string.
int addcount =
addchar - 48;//Subtract 48 because of ASCII code.
string val =
acslcell.substr(0,addcount);//Find values to be added.
int leftcount = 8
- (addcount * 2);//Figure out how many characters are needed.
string end =
acslcell.substr(addcount,leftcount);//Take the part of the string that is
needed.
string a = val +
val + end;//Set the answer.
cout<<a<<endl;//cout
the answer.
}else if(opcheck2
== "subtract"){//Subtract the 8-bit string.
string num =
op.erase(0,8);//Eliminate the subtract from the string.
char subtractchar
= num[0];//Take the number character.
int subtractcount
= subtractchar - 48;//Subtract 48 because of ASCII code.
string
flip;//Flipped acslcell.
for(int i = 0; i
< 8; i++){//For loop for the flipping.
char letter =
acslcell[i];//Letter to be added.
flip = letter +
flip;//Add the letter.
}
string val =
flip.substr(0,subtractcount);//Find values to be added.
int leftcount = 8
- (subtractcount * 2);//Figure out how many characters are needed.
string end =
flip.substr(subtractcount,leftcount);//Take the part of the string that is
needed.
string a = val +
val + end;//Set the answer.
string
a2;//Answer to be flipped to.
for(int i = 0; i
< 8; i++){//For loop for the flipping.
char letter =
a[i];//Letter to be added.
a2 = letter +
a2;//Add the letter.
}
cout<<a2<<endl;//cout
the answer.
}
}
int main(){
for(int i = 0; i
< 5; i++){
cell();
}
return 0;
}