首页 > 技术文章 > sicily 1028 Hanoi Tower Sequence

dominjune 2015-04-22 09:22 原文

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int a[250];
 6 
 7 int cal(int a[],int n) {
 8     int cnt=1;
 9     while (a[n-1]%2==0) {
10         cnt++;
11         for (int i=0,temp=0;i<n;i++) {
12             temp=temp*10+a[i];
13             a[i]=temp/2;
14             temp%=2;
15         }
16     }
17     return cnt;
18 }
19 
20 int main()
21 {
22     int t;
23     cin >> t;
24     int count=0;
25     while(t--)
26     {
27         string s;
28         cin >> s;
29         int len = s.size();
30         for(int i=0; i<len; i++)
31             a[i] = s[i]-'0';
32         cout << "Case " << ++count << ": ";
33             
34         cout << cal(a, len) << endl;
35         if(t != 0)
36             cout << endl;
37     }
38     return 0;
39 }

 

推荐阅读