Created
December 24, 2014 15:12
-
-
Save kenornotes/8cf564f8b3bb84d243df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
//判定是不是一串1 | |
int isOnes(int n) { | |
while(n > 0) { | |
if(n % 10 != 1) | |
return 0; | |
n /= 10; | |
} | |
return 1; | |
} | |
int ones(int n) { | |
int count = 0, times = 1; //count for 計算位數, times for 乘數 | |
int tmp = n; | |
//若不是Ones就繼續乘下去 | |
while(isOnes(tmp) != 1) { | |
tmp = n * times; | |
times++; | |
} | |
//計算位數 | |
while(tmp > 0) { | |
count++; | |
tmp /= 10; | |
} | |
return count; | |
} | |
int main() { | |
int n, i, t; | |
scanf("%d", &n); | |
printf("%d\n", ones(n)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment