fork(2) download
  1.  
  2. #include<string>
  3. struct IO {
  4. #include <cstdio>
  5. #include <iostream>
  6. using std::string;
  7. char buf[1 << 20], * ptr; // 1 MB output buffer
  8. char tmp[1 << 10];
  9. // fast input routines
  10. char cur;
  11. inline char nextChar() { return cur = getc_unlocked(stdin); }
  12. inline char peekChar() { return cur; }
  13. inline operator bool() { return (peekChar() != 0); }
  14. inline static bool isBlank(char c) { return (c < '.' && c); }
  15. inline bool skipBlanks() { while (isBlank(nextChar())); return peekChar() != 0; }
  16. inline IO& operator >> (char & c) { c = nextChar(); return *this; }
  17. inline IO& operator >> (char * buf) {
  18. if (skipBlanks()) {
  19. if (peekChar()) {
  20. *(buf++) = peekChar();
  21. while (!isBlank(nextChar())) *(buf++) = peekChar();
  22. } *(buf++) = 0; } return *this; }
  23. inline IO& operator >> (string & s) {
  24. if (skipBlanks()) { s.clear(); s += peekChar();
  25. while (!isBlank(nextChar())) s += peekChar(); }
  26. return *this; }
  27. inline IO& operator >> (double & d) { if ((*this) >> tmp) sscanf(tmp, "%lf", &d); return *this; }
  28.  
  29. #define defineInFor(intType) \
  30. inline IO& operator >>(intType & n) { \
  31. if (skipBlanks()) { \
  32. int sign = +1; \
  33. if (peekChar() == '-') { \
  34. sign = -1; \
  35. n = nextChar() - '0'; \
  36. } else \
  37. n = peekChar() - '0'; \
  38. while (!isBlank(nextChar())) { \
  39. n *= 10; \
  40. n += peekChar() - '0'; \
  41. } \
  42. n *= sign; \
  43. } \
  44. return *this; \
  45. }
  46.  
  47. defineInFor(int)
  48. defineInFor(unsigned int)
  49. defineInFor(long long)
  50. defineInFor(unsigned long long)
  51. defineInFor(short)
  52. defineInFor(unsigned short)
  53.  
  54. // fast output routines
  55. IO() { cur = 0; ptr = buf; }
  56. void flush() { fwrite(buf, 1, ptr - buf, stdout); ptr = buf; }
  57. ~IO() { flush(); }
  58. inline void putChar(char c) {
  59. if (ptr >= buf + sizeof(buf))
  60. flush();
  61. *ptr++ = c;
  62. #ifndef ONLINE_JUDGE
  63. flush(); // always flush when local
  64. #endif
  65. }
  66. inline IO& operator << (char c) { putChar(c); return *this; }
  67. inline IO& operator << (char * s) { while (*s) putChar(*s++); return *this; }
  68. inline IO& operator << (string & s) { for (int i = 0; i < (int)s.size(); ++i) putChar(s[i]); return *this; }
  69. char * toString(double d) { sprintf(tmp, "%lf%c", d, '\0'); return tmp; }
  70. inline IO& operator << (double d) { return (*this) << toString(d); }
  71.  
  72. #define defineOutFor(intType) \
  73. inline char * toString(intType n) { \
  74. char * p = (tmp + 30); \
  75. *p-- = 0; \
  76. if (n == 0) *p-- = '0'; \
  77. else { \
  78. bool isNeg = 0; \
  79. if (n < 0) isNeg = 1, n = -n; \
  80. while (n > 0) *p-- = (n % 10) + '0', n /= 10; \
  81. if (isNeg) *p-- = '-'; \
  82. } \
  83. return p + 1; \
  84. } \
  85. inline IO& operator << (intType n) { return (*this) << toString(n); }
  86.  
  87. defineOutFor(int)
  88. defineOutFor(unsigned int)
  89. defineOutFor(long long)
  90. defineOutFor(unsigned long long)
  91. defineOutFor(short)
  92. defineOutFor(unsigned short)
  93.  
  94. #define endl ('\n')
  95. #define cout __io__
  96. #define cin __io__
  97. } __io__;
  98.  
  99. int getline(IO & io, string & s) {
  100. s.clear(); char c;
  101. while ((io >> c) && (c != '\n' && c != '\r')) s += c;
  102. if (c == '\r') io >> c; // CR LF found -> skip \n
  103. return (int)s.size();
  104. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Amit Upadhyay
compilation info
In file included from /usr/include/c++/4.7/cstdio:44:0,
                 from prog.cpp:4:
/usr/include/stdio.h:30:1: error: expected unqualified-id before string constant
prog.cpp:104:1: error: expected ‘}’ at end of input
prog.cpp:104:1: error: expected unqualified-id at end of input
stdout
Standard output is empty