标签:space clu noip algo 文件 file out names mes
#define LONG
using namespace std;
int main()
{
#ifdef LONG
freopen("P5744_1.in", "r", stdin);
freopen("P5744_1.out", "w", stdout);
#endif
巴拉巴拉
}
在没有定义ifdef后面的东西的时候里面的程序不会运行,只有定义了LONG之后才会运行里面的程序。里面的程序运行后会从文件里读取输入,将输出写入输出文件
这个方法是正常C语言的方法,应该没什么大问题,这里贴两份代码
#include <iostream>
#include<stdio.h>
#include <string>
#include<string.h>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
struct Student {
string name;
int age;
int NOIP;
};
int main()
{
FILE* fin, * fout;
fin=fopen("P5744_1.in", "rb");
fout=fopen("P5744_1.out", "wb");
int n;
fscanf(fin, "%d", &n);
Student* s = new Student[n];
for (int i = 0; i < n; i++) {
fscanf(fin, "%s %d %d", &s[i].name, &s[i].age, &s[i].NOIP);
s[i].age++;
s[i].NOIP = (s[i].NOIP * 1.2 > 600) ? 600 : int(s[i].NOIP * 1.2);
}
int i;
for (i = 0; i < n - 1; i++) {
fprintf(fout, "%s %d %d\n", &s[i].name, s[i].age, s[i].NOIP);
}
fprintf(fout, "%s %d %d", &s[i].name, s[i].age, s[i].NOIP);
fclose(fin);
fclose(fout);
}
#include <iostream>
#include<stdio.h>
#include <string>
#include<string.h>
#include<math.h>
#include<vector>
#include<algorithm>
#define LONG
using namespace std;
struct Student {
string name;
int age;
int NOIP;
};
int main()
{
#ifdef LONG
freopen("P5744_1.in", "r", stdin);
freopen("P5744_1.out", "w", stdout);
#endif
FILE* fin, *fout;
fin = stdin;
fout = stdout;
int n;
fscanf(fin, "%d", &n);
Student* s = new Student[n];
for (int i = 0; i < n; i++) {
fscanf(fin, "%s %d %d", &s[i].name, &s[i].age, &s[i].NOIP);
s[i].age++;
s[i].NOIP = (s[i].NOIP * 1.2 > 600) ? 600 : int(s[i].NOIP * 1.2);
}
int i;
for (i = 0; i < n - 1; i++) {
fprintf(fout, "%s %d %d\n", &s[i].name, s[i].age, s[i].NOIP);
}
fprintf(fout, "%s %d %d", &s[i].name, s[i].age, s[i].NOIP);
}
标签:space clu noip algo 文件 file out names mes
原文地址:https://www.cnblogs.com/Alan-kx/p/14364199.html