2013年11月4日 星期一

[UVA] 12416 - Excessive Space Remover


#include<stdio.h>
char s[1000005];
int main(){
    int max,add,i;
    while(gets(s)){
        max=add=0;
        for(i=0;s[i];i++){
            if(s[i]==' '){
                add++;
                if(add>max) max=add;
            }
            else add=0;
        }
        add=0;
        while(max>1)
            add++,max=max/2+max%2;
        printf("%d\n",add);
    }
}

沒有留言:

張貼留言