Jugde for Tsinsen(Ver. Cpp)

#include 
#include 

using namespace std;

int main(int argc, char **argv)
  {
    FILE *f1 = fopen(argv[2], "r");
    FILE *f2 = fopen(argv[3], "r");
    FILE *f3 = fopen(argv[4], "w");
    
    if (f1 == NULL)
      {
        fprintf(f3, "0\n");
        return 0;
      }
    
    double x, y; int i = 0;
    
    for ( ; ++i && fscanf(f2, "%lf", &x) != EOF; )
      {
        if (fscanf(f1, "%lf", &y) != 1)
          {
            fprintf(f3, "0\n");
            fclose(f1);
            fclose(f2);
            fclose(f3);
            return 0;
          }
        if (fabs(x - y) > 0.001)
          {
            fprintf(f3, "0\n%d: %lf", i, fabs (x - y));
            fclose(f1);
            fclose(f2);
            fclose(f3);
            return 0;
          }
      }
    
    fprintf(f3, "1\n");
    fclose(f1);
    fclose(f2);
    fclose(f3);
    
    return 0;
  }



你可能感兴趣的:(Jugde for Tsinsen(Ver. Cpp))