posts - 100,  comments - 15,  trackbacks - 0
/*
 * hit1214.cpp
 *  
 *  Created on: 2010-10-3
 *      Author: wyiu
 
*/
#include 
<iostream>
#include 
<string>
#include 
<cstdio>
#include 
<cstring>
using namespace std;

unsigned f[]
={112358132134,
        
5589144233377610987159725844181,
        
67651094617711286574636875025121393196418317811514229,
        
83204013462692178309352457857028879227465,14930352,24157817,39088169,63245986,
        
102334155165580141267914296433494437,701408733113490317018363119032971215073
};

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 阅读(274) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理