Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include<math.h>
- int function(char str[]);
- int digit(int n);
- int main() {
- char str[1000010];
- while(1) {
- scanf("%s", &str);
- if(strcmp(str,"END")==0) break;
- printf("%d\n", function(str));
- }
- return 0;
- }
- int function(char str[]) {
- if(strcmp(str, "1")==0) return 1;
- int c=1, l=strlen(str);
- while(l!=1) {
- l=digit(l);
- c++;
- if(l==1) return ++c;
- }
- return ++c;
- }
- int digit(int n) {
- int c=0;
- while(n!=0) {
- n/=10;
- c++;
- }
- return c;
- }
Add Comment
Please, Sign In to add comment