fork(5) download
  1.  
  2. struct itostr_helper {
  3. static unsigned out[10000];
  4.  
  5. itostr_helper() {
  6. for (int i = 0; i < 10000; i++) {
  7. unsigned v = i;
  8. char * o = (char*)(out + i);
  9. o[3] = v % 10 + '0';
  10. o[2] = (v % 100) / 10 + '0';
  11. o[1] = (v % 1000) / 100 + '0';
  12. o[0] = (v % 10000) / 1000;
  13. if (o[0]) o[0] |= 0x30;
  14. else if (o[1] != '0') o[0] |= 0x20;
  15. else if (o[2] != '0') o[0] |= 0x10;
  16. else o[0] |= 0x00;
  17. }
  18. }
  19. };
  20. unsigned itostr_helper::out[10000];
  21.  
  22. itostr_helper hlp_init;
  23.  
  24. template <typename T>
  25. std::string itostr(T o) {
  26. typedef itostr_helper hlp;
  27.  
  28. unsigned blocks[3], *b = blocks + 2;
  29. blocks[0] = o < 0 ? ~o + 1 : o;
  30. blocks[2] = blocks[0] % 10000; blocks[0] /= 10000;
  31. blocks[2] = hlp::out[blocks[2]];
  32.  
  33. if (blocks[0]) {
  34. blocks[1] = blocks[0] % 10000; blocks[0] /= 10000;
  35. blocks[1] = hlp::out[blocks[1]];
  36. blocks[2] |= 0x30303030;
  37. b--;
  38. }
  39.  
  40. if (blocks[0]) {
  41. blocks[0] = hlp::out[blocks[0] % 10000];
  42. blocks[1] |= 0x30303030;
  43. b--;
  44. }
  45.  
  46. char* f = ((char*)b);
  47. f += 3 - (*f >> 4);
  48.  
  49. char* str = (char*)blocks;
  50. if (o < 0) *--f = '-';
  51. return std::string(f, (str + 12) - f);
  52. }
  53.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty