Skip to content

Instantly share code, notes, and snippets.

@kenornotes
Created December 24, 2014 15:12
Show Gist options
  • Save kenornotes/8cf564f8b3bb84d243df to your computer and use it in GitHub Desktop.
Save kenornotes/8cf564f8b3bb84d243df to your computer and use it in GitHub Desktop.
#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