Skip to content

Instantly share code, notes, and snippets.

@behitek
Last active July 27, 2021 12:40
Show Gist options
  • Select an option

  • Save behitek/fc111c0d0b40a08d1b407c207fa8a53e to your computer and use it in GitHub Desktop.

Select an option

Save behitek/fc111c0d0b40a08d1b407c207fa8a53e to your computer and use it in GitHub Desktop.

Lưu ý

  • Nếu đã thẻ có tag phù hợp, hãy dùng lại
  • Nếu cần tạo tag mới, cố gắng dùng từ tiếng Việt, ngắn gọn, viết thường
  • DisplayID viết hoa, ngắn gọn (Nếu đề trong sheet thì lấy ID trong đó)
  • Tiêu đề ngắn gọn, k cần quá dài, không bắt buộc mô tả chi tiết bài tập (vì có mô tả bài tập lo rồi)
  • Mô tả đề bài rõ ràng, không có nhập nhằng
  • Mô tả input/output rõ ràng (có giới hạn phạm vi dữ liệu nếu cần)
  • Bộ test cố gắng bao phủ được đầy đủ các trường hợp khác nhau
  • Số lượng bộ test nên là ước của số điểm (Dễ: 100đ, TB: 150đ, Khó: >= 200đ)
  • Type: ACM/OI -> chọn OI
  • IO Mode: Standard IO

Latex

Markdown

Special Judge

#include <bits/stdc++.h>

#define AC 0
#define WA 1
#define ERROR -1

int spj(std::ifstream &input, std::ifstream &user_output);

int main(int argc, char *args[]){
    int result;
    if(argc != 3){
        std::cout << "Usage: spj x.in x.out\n";
        return ERROR;
    }
    std::ifstream input(args[1]);
    std::ifstream user_output(args[2]);
    if(input.fail() || user_output.fail()){
        std::cout << "Failed to open output file\n";
        input.close();
        user_output.close();
        return ERROR;
    }

    result = spj(input, user_output);
    std::cout << "result: " << result << "\n";

    input.close();
    user_output.close();
    return result;
}

int spj(std::ifstream &input, std::ifstream &user_output){
    int a, b, sum, sub, mul;
    std::string div;
    input >> a >> b;
    user_output >> sum;
    user_output >> sub;
    user_output >> mul;
    user_output >> div;

    bool ok = true;

    if (fabs(a + b - sum) != 0) {
    	return WA;
    }

    if (fabs(a - b - sub) != 0) {
    	return WA;
    }
    if (fabs(a * b - mul) != 0) {
    	return WA;
    }
    if (b == 0 && div != "INF" && div != "inf") {
    	return WA;	
    }
    double val = std::stod(div);
    if (fabs((double)a / b - val) >=  0.01) {
    	return WA;
    }
    return AC;
  	
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment