fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. long long s = 0;
  5. char c = 0;
  6. while(1) {
  7. scanf("%c", &c);
  8. if(c == '\n') {
  9. break;
  10. }
  11. char index = 2 * (c - '0');
  12. long long current = (((s >> index) & 0xFF) + 1) << index;
  13. long long clear = ~(0xFF << index);
  14. s &= clear;
  15. s |= current;
  16. }
  17.  
  18. while(s) {
  19. char last_num = 0;
  20. long long temp_s = s;
  21. while((temp_s = temp_s >> 2) > 0) {
  22. ++last_num;
  23. }
  24. printf("%d", last_num);
  25. char index = 2 * last_num;
  26. long long current = (((s >> index) & 0xFF) - 1) << index;
  27. long long clear = ~(0xFF << index);
  28. s &= clear;
  29. s |= current;
  30. }
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 15232KB
stdin
123456078
stdout
876543210