/*
* hit1214.cpp
*
* Created on: 2010-10-3
* Author: wyiu
*/
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;
unsigned f[]={1, 1, 2, 3, 5, 8, 13, 21, 34,
55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181,
6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229,
832040, 1346269, 2178309, 3524578, 5702887, 9227465,14930352,24157817,39088169,63245986,
102334155, 165580141, 267914296, 433494437,701408733, 1134903170, 1836311903, 2971215073
};
bool check(string s)
{
for(int i=0; i<s.length()-1; i++)
if(s[i]=='1' && s[i+1]=='1')
return false;
return true;
}
int main()
{
int n;
unsigned val;
int len;
string s;
int i;
scanf("%d", &n);
while(n--)
{
cin>>s;
val = 0;
len = s.length();
for(i=len-1; i>=0; --i)
{
if(s[i] == '1')
val += f[len-i];
}
printf("%u in decimal, ", val);
fflush(stdout);
if(check(s))
{
printf("already in standard form\n");
fflush(stdout);
continue;
}
for(i=0; i<len && s[i]=='0'; i++);
string stds(s.substr(i, len-i));
bool changed;
while(!check(stds))
{
for(i=0, changed=false; i<stds.length()-1; i++)
{
if(stds[i]=='1' && stds[i+1]=='1')
{
stds[i]='0';
stds[i+1]='0';
if(i==0)
stds = string("1")+stds;
else stds[i-1]='1';
changed = true;
}
if(changed)
break;
}
}
cout<<"whose standard form is "<<stds<<endl;
}
return 0;
}
posted on 2010-10-05 15:13
wyiu 阅读(327)
评论(0) 编辑 收藏 引用