OK = false; while (!OK) { in(); i = n; while (a[i] == '1') a[i--] = '0'; if (i==0) OK = true; else { a[i] = '1'; } }