Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Judge: "4. Score is source length"
- #include "spoj.h"
- #include <stdlib.h>
- using namespace std;
- // <0-255> normal, - 1 white, -2 eof
- int getChar(FILE *f, bool ignWhite) {
- bool white;
- int ch;
- do {
- if ((ch = getc(f))==EOF)
- return -2;
- if (ch==' ' || ch=='\n' || ch=='\t' || ch=='\r')
- white=true;
- else white=false;
- } while (ignWhite && white);
- if (white)
- return -1;
- return ch;
- }
- void myexit() {
- 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
- exit(SPOJ_RV_POSITIVE);
- }
- int main(void) {
- spoj_init();
- int ch1 = getChar(spoj_t_out, true);
- int ch2 = getChar(spoj_p_out, true);
- while (ch1 == ch2) {
- if (ch1==-2)
- myexit();
- bool ignWhite;
- if (ch1==-1)
- ignWhite =true;
- else
- ignWhite=false;
- ch1 = getChar(spoj_t_out, ignWhite);
- ch2 = getChar(spoj_p_out, ignWhite);
- };
- if (ch1 == -2 && ch2 == -1 && getChar(spoj_p_out, true)==-2 )
- myexit();
- if (ch2 == -2 && ch1 == -1 && getChar(spoj_t_out, true)==-2)
- myexit();
- return SPOJ_RV_NEGATIVE;
- }
Add Comment
Please, Sign In to add comment