arjunarul

Code Golf judge

Jan 26th, 2020
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. // Judge: "4. Score is source length"
  2.  
  3. #include "spoj.h"
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. // <0-255> normal, - 1 white, -2 eof
  9. int getChar(FILE *f, bool ignWhite) {
  10.     bool white;
  11.     int ch;
  12.     do {
  13.         if ((ch = getc(f))==EOF)
  14.             return -2;
  15.         if (ch==' ' || ch=='\n' || ch=='\t' || ch=='\r')
  16.             white=true;
  17.         else white=false;
  18.     } while (ignWhite && white);
  19.     if (white)
  20.         return -1;
  21.     return ch;
  22. }
  23.  
  24. void myexit() {
  25.   fprintf(spoj_score, "%d\n", spoj_file_length(spoj_t_src));  // spoj_file_length can be found in spoj.c in http://discuss.spoj.com/t/how-to-add-problem-into-spoj/693/4
  26.   exit(SPOJ_RV_POSITIVE);
  27. }
  28.  
  29. int main(void) {
  30.     spoj_init();
  31.     int ch1 = getChar(spoj_t_out, true);
  32.     int ch2 = getChar(spoj_p_out, true);
  33.     while (ch1 == ch2) {
  34.         if (ch1==-2)
  35.             myexit();
  36.         bool ignWhite;
  37.         if (ch1==-1)
  38.             ignWhite =true;
  39.         else
  40.             ignWhite=false;
  41.         ch1 = getChar(spoj_t_out, ignWhite);
  42.         ch2 = getChar(spoj_p_out, ignWhite);
  43.     };
  44.     if (ch1 == -2 && ch2 == -1 && getChar(spoj_p_out, true)==-2 )
  45.         myexit();
  46.     if (ch2 == -2 && ch1 == -1 && getChar(spoj_t_out, true)==-2)
  47.         myexit();
  48.     return SPOJ_RV_NEGATIVE;
  49. }
Add Comment
Please, Sign In to add comment