Pages

Showing posts with label Ad Hoc. Show all posts
Showing posts with label Ad Hoc. Show all posts

Saturday, June 2, 2012

11498 - Division of Nlogonia



// main.cpp
// 11498 - Division of Nlogonia
//
// Created by Panks on 29/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int k,n,m;
int x,y;
cin>>k;
while (k!=0) {
cin>>n>>m;
while (k--) {
cin>>x>>y;
if (x==n||y==m) {
cout<<"divisa\n";
continue;
}else{
if (x<n) {
if (y<m) {
cout<<"SO\n";
}else{
cout<<"NO\n";
}

}else{

if (y<m) {
cout<<"SE\n";
}else{
cout<<"NE\n";
}

}
}
}
cin>>k;
}

return 0;
}


11340 - Newspaper


//
// main.cpp
// 11340 - Newspaper
//
// Created by Panks on 31/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <map>
#include <cstdio>
using namespace std;
int main (int argc, const char * argv[])
{

int t,in;
double answer;
char letter;
int vals;
string line;
map<char, int> values;

cin>>t;
while (t--) {

answer=0;
cin>>in;
while (in--) {
cin>>letter>>vals;
values.insert(pair<char, int>(letter, vals));
}
cin>>in;
getchar();
while (in--) {
getline(cin, line);
for (int i=0; i<line.size() ; i++) {
if (values[line[i]]) {
answer+=values[line[i]];
}
}
}
answer/=100;
printf("%.2f$\n", answer);

values.clear();

}
return 0;
}


11150 - Cola

Just scribe a little on paper, you would get it. ;)

//
// main.cpp
// 11150 - Cola
//
// Created by Panks on 29/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

int a, tmp;
while (cin>>a) {
if (a==1||a==0) {
cout<<a<<endl;
continue;
}
tmp=a;
a=a+a/2;
a=a-a%3;
cout<<tmp+(a/3)<<endl;
}
return 0;
}

11044 - Searching for Nessy


//
// main.cpp
// 11044 - Searching for Nessy
//
// Created by Panks on 29/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

int t;
double a,b, froma, fromb;
int ifroma, ifromb;
cin>>t;
while (t--) {
cin>>a>>b;
a-=2;
b-=2;
froma=a/3.0;
fromb=b/3.0;

if (froma-(int)froma!=0) {
ifroma=(int)froma+1;
}else{
ifroma=(int)froma;
}


if (fromb-(int)fromb!=0) {
ifromb=(int)fromb+1;
}else{
ifromb=(int)fromb;
}

cout<<ifroma*ifromb<<endl;
}
return 0;
}

10921 - Find the Telephone


//
// main.cpp
// 10921 - Find the Telephone
//
// Created by Panks on 28/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;


void doit(char a);
string *str=new string[8];
using namespace std;
int main (int argc, const char * argv[])
{

str[0]="ABC", str[1]="DEF", str[2]="GHI", str[3]="JKL", str[4]="MNO", str[5]="PQRS", str[6]="TUV", str[7]="WXYZ";
string input;
while (getline(cin, input)){
for_each(input.begin(), input.end(), doit);
cout<<endl;
}
return 0;
}


void doit(char a){
bool done=false;
for (int i=0; i<8; i++) {
if (count(str[i].begin(), str[i].end(), a)) {
cout<<i+2;
done=true;
}
}

if (!done) {
cout<<a;
}
}

10812 - Beat the Spread!


//
// main.cpp
// Problem D: Beat the Spread!
// Created by Panks on 28/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

int t, a, b;
cin>>t;
while (t--) {
cin>>a>>b;
if(a>=b&&a>=0&&b>=0&&((a+b)%2==0))
{
int c=(a+b)/2;
cout<<c<<" "<<a-c<<endl;

}else{
cout<<"impossible\n";
}
}
return 0;
}

10683 - The decadary watch


//
// main.cpp
// 10683 - The decadary watch
// Created by Panks on 28/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <sstream>
using namespace std;
long double mult = 10000000.0/8640000.0;
long long int secs1;
int ans;
string convertInt(int number);
string convertInt(int number)
{
stringstream ss; //create a stringstream
ss << number; //add number to the stream
return ss.str(); //return a string with the contents of the stream
}

int main (int argc, const char * argv[])
{

string input;
int h1, m1, s1, c1, h2, m2, s2, c2;
while (getline(cin, input)) {
h1=(input[0]-'0')*10+(input[1]-'0');
m1=(input[2]-'0')*10+(input[3]-'0');
s1=(input[4]-'0')*10+(input[5]-'0');
c1=(input[6]-'0')*10+(input[7]-'0');
secs1=h1*360000+m1*6000+s1*100+c1;

ans=secs1*mult;
string tocheck=convertInt(ans);
int len=7-(tocheck.size());
while (len--) {
cout<<'0';
}

cout<<ans<<endl;
}
return 0;
}

10420 - List of Conquests


//
// main.cpp
// 10420 - List of Conquests
//
// Created by Panks on 28/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <map>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

map<string, int> store;
vector<string> onlyplace;
bool cmpit(pair<string, int> a);
bool cmpit(pair<string, int> a){
return 0;
}

void printit(string place);
void printit(string place){

cout<<place<<" "<<store[place]<<endl;
}
int main (int argc, const char * argv[])
{
int t;
cin>>t;
getchar();
while (t--) {
string name, place;
cin>>place;
getchar();
getline(cin, name);
if (store[place]) {
store[place]++;
}else{
onlyplace.push_back(place);
store.insert(pair<string, int>(place, 100));
store[place]++;
}
}

sort(onlyplace.begin(), onlyplace.end());
for_each(onlyplace.begin(), onlyplace.end(), printit);
return 0;
}

10363 - Tic Tac Toe


//
// main.cpp
// 10363 - Tic Tac Toe
//
// Created by Panks on 28/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main (int argc, const char * argv[])
{

// insert code here...
int t;
string row1, row2, row3;
cin>>t;
while (t--) {
bool xwin=0;
bool owin=0;
getchar();
getline(cin, row1);
getline(cin, row2);
getline(cin, row3);
long int countx=0, counto=0;
countx=count(row1.begin(), row1.end(), 'X')+count(row2.begin(), row2.end(), 'X')+count(row3.begin(), row3.end(), 'X');
counto=count(row1.begin(), row1.end(), 'O')+count(row2.begin(), row2.end(), 'O')+count(row3.begin(), row3.end(), 'O');


if (count(row1.begin(), row1.end(), 'X')==3||count(row2.begin(), row2.end(), 'X')==3||count(row3.begin(), row3.end(), 'X')==3) {
xwin=true;
}
if ((row1[0]=='X'&&row2[0]=='X'&&row3[0]=='X') || (row1[1]=='X'&&row2[1]=='X'&&row3[1]=='X') || (row1[2]=='X'&&row2[2]=='X'&&row3[2]=='X')) {
xwin=true;
}
if ((row1[2]=='X'&&row2[1]=='X'&&row3[0]=='X') || (row1[0]=='X'&&row2[1]=='X'&&row3[2]=='X')) {
xwin=true;
}


if (count(row1.begin(), row1.end(), 'O')==3||count(row2.begin(), row2.end(), 'O')==3||count(row3.begin(), row3.end(), 'O')==3) {
owin=true;
}
if ((row1[0]=='O'&&row2[0]=='O'&&row3[0]=='O') || (row1[1]=='O'&&row2[1]=='O'&&row3[1]=='O') || (row1[2]=='O'&&row2[2]=='O'&&row3[2]=='O')) {
owin=true;
}
if ((row1[2]=='O'&&row2[1]=='O'&&row3[0]=='O') || (row1[0]=='O'&&row2[1]=='O'&&row3[2]=='O')) {
owin=true;
}


if(countx>counto+1){
cout<<"no\n";
}else if (counto>countx) {
cout<<"no\n";
}else if(xwin==true && owin==true){
cout<<"no\n";
}else if(owin==true&&counto<countx){
cout<<"no\n";
}else if(xwin==true&&counto>=countx){
cout<<"no\n";
}else
cout<<"yes\n";
}
return 0;
}


10281 - Average Speed


//
// main.cpp
// 10281 - Average Speed
//
// Created by Panks on 27/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
double cspeed=0, tdistane=0;
int gh=0, gm=0, gs=0;
string input;


void updatevalues();
void updatevalues(){
int h=0,m=0,s=0, speed=0;
int i=0;
while (input[i]!=':') {
h=h*10+input[i]-'0';
i++;
}
i++;
while (input[i]!=':') {
m=m*10+input[i]-'0';
i++;
}
i++;
while (input[i]!=' ') {
s=s*10+input[i]-'0';
i++;
}
i++;
while (input[i]!='\0') {
speed=speed*10+input[i]-'0';
i++;
}
double time=(h-gh)+((m-gm)/60.0)+((s-gs)/3600.0);
double dis=time*cspeed;
tdistane=dis+tdistane;
cspeed=speed;
gh=h;
gm=m;
gs=s;
}



int main (int argc, const char * argv[])
{

// insert code here...
int h=0, m=0, s=0;
while (getline(cin, input)) {
if (count(input.begin(), input.end(), ' ')) {
updatevalues();
}else{
int i=0;
h=0; m=0; s=0;
while (input[i]!=':') {
h=h*10+input[i]-'0';
i++;
}
i++;
while (input[i]!=':') {
m=m*10+input[i]-'0';
i++;
}
i++;
while (input[i]!='\0') {
s=s*10+input[i]-'0';
i++;
}

double dist=((h-gh)+((m-gm)/60.0)+((s-gs)/3600.0))*cspeed;
double totaldis=tdistane+dist;
printf("%s %.2f km\n", &input[0], totaldis);


}
}

}


10141 - Request for Proposal


/* ******************************************* */
// \_/\_/\_/\_/---Coded by Panks---\_/\_/\_/\_/ //
/* ******************************************* */


// **********************Headers******************

//C headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cassert>
#include<climits>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<clocale>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>

//containers
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<complex>
#include<string>
#include<stack>
#include<bitset>
#include<istream>
#include<valarray>

//IOs
#include<iostream>
#include<sstream>
#include<iomanip>
#include<fstream>
#include<exception>
#include<ios>
#include<iosfwd>
#include<ostream>
#include<iterator>
#include<stdexcept>
#include<streambuf>

//algorithm & miscellaneous
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<limits>
#include<locale>
#include<memory>
#include<new>
/* ********************************************** */


////////////////////SHORTHANDS\\\\\\\\\\\\\\\\\\\\\

#define ull unsigned long long
#define ll long long

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,n) FOR(i,0,n-1)

#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REPD(i,n) FOR(i,n-1,0)

#define testcase(t) int t;scanf("%d",&t);while(t--)
#define s(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)

#define p(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)

#define pn(x) printf("%d\n",x)
#define pln(x) printf("%lld\n",x)
#define psn(x) printf("%s\n",x)

#define all(c) c.begin(),c.end()
//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\


// ---------------Fast IO using getchar-------------- \\
// will accept values 9-digits in int and 19-digits in long long on my system


int getint(){
int c = 'a';
while (!(c >= '0' && c <= '9') && c != '-')
c = getchar();
int c2;
if (c != '-')
c2 = c;
else
c2 = '0';
int res = 0;
while((c2 >= '0' && c2 <= '9')){
res = (res << 3) + (res << 1) + (c2 - '0');

c2 = getchar();
}
return res * (c == '-' ? -1 : 1);
}
// ------------------------------------------------- \\

//------------------Actual Code--------------------- \\

using namespace std;

int main (int argc, const char * argv[])
{

int n, p,count=0;
string req, name, togive;
double price, minprice;
int met, maxmet;
cin>>n>>p;
while (n!=0) {
count++;
getchar();
while (n--) {
getline(cin, req);
}
met=maxmet=0;
price=minprice=0;
while (p--) {
getline(cin, name);
cin>>price>>met;
if (met>maxmet) {
maxmet=met;
minprice=price;
togive=name;
}else if(met==maxmet){
if (price<minprice) {
maxmet=met;
minprice=price;
togive=name;
}
}

getchar();
while (met--) {
getline(cin, req);
}
}

if (count>1) {
cout<<endl;
}
cout<<"RFP #"<<count<<endl<<togive<<endl;


cin>>n>>p;
}
return 0;
}

10082 - WERTYU

You can combine all the arrays in one and can do a lot better :) , I was just rushing through when I coded these.


//
// main.cpp
// WERTY
//
// Created by Panks on 27/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;



#define ull unsigned long long
#define ll long long

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,n) FOR(i,0,n-1)

#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REPD(i,n) FOR(i,n-1,0)

#define testcase(t) int t;scanf("%d",&t);while(t--)
#define s(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)

#define p(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)

#define pn(x) printf("%d\n",x)
#define pln(x) printf("%lld\n",x)
#define psn(x) printf("%s\n",x)

#define all(c) c.begin(),c.end()




string row1="`1234567890-=", row2="QWERTYUIOP[]\?", row3="ASDFGHJKL;'", row4="ZXCVBNM,./<";

void replaceit(char a);
void replaceit(char a){
if (a==' ') {
cout<<" ";
}
string::iterator pos;

if(count(row1.begin(), row1.end(), a)){
pos=find(all(row1), a);
pos--;
cout<<*pos;
}else if(count(row2.begin(), row2.end(), a)){
pos=find(all(row2), a);
pos--;

cout<<*pos;
}else if(count(row3.begin(), row3.end(), a)){
pos=find(all(row3), a);
pos--;

cout<<*pos;
}else if(count(row4.begin(), row4.end(), a)){
pos=find(all(row4), a);
pos--;
cout<<*pos;
}
}

int main (int argc, const char * argv[])
{
string input;
while(getline(cin, input)){
for_each(input.begin(), input.end(), replaceit);
cout<<endl;
}

}


941 - Permutations



/* ******************************************* */
// \_/\_/\_/\_/---Coded by Panks---\_/\_/\_/\_/ //
/* ******************************************* */


// **********************Headers******************

//C headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cassert>
#include<climits>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<clocale>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>

//containers
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<complex>
#include<string>
#include<stack>
#include<bitset>
#include<istream>
#include<valarray>

//IOs
#include<iostream>
#include<sstream>
#include<iomanip>
#include<fstream>
#include<exception>
#include<ios>
#include<iosfwd>
#include<ostream>
#include<iterator>
#include<stdexcept>
#include<streambuf>

//algorithm & miscellaneous
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<limits>
#include<locale>
#include<memory>
#include<new>
/* ********************************************** */


////////////////////SHORTHANDS\\\\\\\\\\\\\\\\\\\\\

#define ull unsigned long long
#define ll long long

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,n) FOR(i,0,n-1)

#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REPD(i,n) FOR(i,n-1,0)

#define testcase(t) int t;scanf("%d",&t);while(t--)
#define s(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)

#define p(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)

#define pn(x) printf("%d\n",x)
#define pln(x) printf("%lld\n",x)
#define psn(x) printf("%s\n",x)

#define all(c) c.begin(),c.end()
//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\


// ---------------Fast IO using getchar-------------- \\
// will accept values 9-digits in int and 19-digits in long long on my system

int getint();
int getint(){
int c = 'a';
while (!(c >= '0' && c <= '9') && c != '-')
c = getchar();
int c2;
if (c != '-')
c2 = c;
else
c2 = '0';
int res = 0;
while((c2 >= '0' && c2 <= '9')){
res = (res << 3) + (res << 1) + (c2 - '0');

c2 = getchar();
}
return res * (c == '-' ? -1 : 1);
}
// ------------------------------------------------- \\

//------------------Actual Code--------------------- \\


using namespace std;

bool compit (char a, char b);
bool compit (char a, char b){
return int(a)<int(b);
}

long int factorial(long int n);
long int factorial(long int n){
int a=1;
while (n!=1) {
a*=n;
n--;
}
return a;
}

int main(){

int t;
string input="";
long int no, fact;
cin>>t;
while (t--) {
cin>>input>>no;
sort(all(input), compit);
int a=0;
fact=1;
int long factor=factorial(input.size());
no=no%factor;

if (no!=0) {
while (fact<=no) {
a++;
fact=fact*a;
}
fact/=a;
a--;

}else{
fact=0;
a=0;

}

string ans="";
while (a--) {
ans+=char(int(no/fact)+48);
no=no%fact;
fact/=(a+1);
}
ans+='0';

int long diff=input.size()-ans.size();
if (diff<0) {
diff=0;
}
while (diff--) {
ans='0'+ans;
}


long int len=input.size();
int i=0;
len--;
string final="";
while (len--) {
final+=input[ans[i]-48];
input.erase(input.begin()+ans[i]-48);
i++;
}
cout<<final+input<<endl;

}

}

739 - Soundex Indexing


//
// main.cpp
// Soundex Indexing
//
// Created by Panks on 24/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
using namespace std;



int getcode(char a);

int main (int argc, const char * argv[])
{

string input;
bool done=false;
int i;
string code, ans;
cout<<" NAME SOUNDEX CODE"<<endl;
while (cin>>input) {
done=false;
i=0;
code="";
while (i<input.length()&&!done) {
if(i>0&&(input[i]=='A'||input[i]=='E'||input[i]=='I'||input[i]=='O'||input[i]=='U'||input[i]=='Y'||input[i]=='W'||input[i]=='H'||getcode(input[i])==getcode(input[i-1]))){
i++;
continue;
}
if (code.length()==4) {
done=true;
continue;
}else if(code.length()>0&&code.length()<4){
code=code+char(getcode(input[i])+48);
i++;
}else{
code=input[i];
i++;
}
}
if (code.length()!=4) {
while (code.length()!=4) {
code=code+'0';
}
}
ans="";
ans=" "+input;
while (ans.length()!=34) {
ans=ans+' ';
}
ans=ans+code;
cout<<ans<<endl;
}
cout<<" END OF OUTPUT"<<endl;
return 0;
}

int getcode(char a){
if(a=='B'||a=='P'||a=='F'||a=='V'){
return 1;
}else if(a=='D'||a=='T'){
return 3;
}else if(a=='L'){
return 4;
}else if(a=='M'||a=='N'){
return 5;
}else if(a=='R'){
return 6;
}else if(a=='C'||a=='S'||a=='K'||a=='G'||a=='J'||a=='Q'||a=='X'||a=='Z'){
return 2;
}else{
return -1;
}
}

661 - Blowing Fuses



//
// main.cpp
// Blowing Fuses
//
// Created by Panks on 23/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <vector>
using namespace std;
int main (int argc, const char * argv[])
{


int n,m,c;
int getit;
int count=0;

int* devpowr=new int[20];
bool* devstat=new bool[20];

cin>>n>>m>>c;
while (n!=0) {
count++;
for (int i=0; i<n; i++) {
cin>>getit;
devpowr[i]=getit;
devstat[i]=false;
}
int total=0,mtotal=0;
int tmp;
for (int i=1; i<=m; i++) {
cin>>tmp;
tmp--;
if(devstat[tmp]==false){
devstat[tmp]=true;
total+=devpowr[tmp];
mtotal=max(mtotal, total);
if(total>c){
cout<<"Sequence "<<count<<"\nFuse was blown.\n\n";
for(int r = i + 1; r <= m; r++) {
cin >> tmp;}

break;
}
}else{
devstat[tmp]=false;
total-=devpowr[tmp];
}

if(i==m){
cout<<"Sequence "<<count<<"\nFuse was not blown.\nMaximal power consumption was "<<mtotal<<" amperes.\n\n";
break;
}
}
cin>>n>>m>>c;
}
return 0;
}


573 - The Snail



//
// main.cpp
// The Snail
//
// Created by Panks on 23/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <cmath>
using namespace std;
int main (int argc, const char * argv[])
{


double h, u, d;
int f;
cin>>h>>u>>d>>f;

while (h!=0) {
double tmp=0;
int count=0;
double df=u*f/100.0;
while (1) {
tmp=tmp+u;
count++;
if(tmp>h){
cout<<"success on day "<<count<<endl;
break;
}
tmp-=d;
if(tmp<0&&count>0){
cout<<"failure on day "<<count<<endl;
break;
}
u=u-df;
if (u<0) {
u=0;
}
}

cin>>h>>u>>d>>f;
}

return 0;
}


483 - Word Scramble




//
// main.cpp
// Word Scramble
//
// Created by Panks on 23/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{


string a, tmp;
char *input=new char[100000];
while(cin.getline(input, 100000)){
int i=0;
here:
tmp="";
while (input[i]!=' '&&input[i]!='\0') {
tmp=input[i]+tmp;
i++;
}
cout<<tmp;

if(input[i]!='\0'){
cout<<input[i];
i++;
goto here;
}else{
cout<<endl;
}


}
return 0;
}



100 - The 3n + 1 problem



//
// main.cpp
// UVa
//
// Created by Panks on 06/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;

int getDist(int num);

int main (void)
{
int a,b,maxi=0,c,d;
while(cin>>a>>b){
maxi=0;
c=max(a,b);
d=c==a?b:a;
for (int i=d; i<=c; i++) {
maxi=max(maxi, getDist(i));
}
printf("%d %d %d\n", a,b,maxi);
}
return 0;
}

int getDist(int num){
int dist=1;
if(num==1)
return 1;
while(1){
if(num%2==0){
num=num/2;
dist++;
if(num==1)
break;
}
else{
num=num*3+1;
dist++;
}
}
return dist;
}