基础技术

1.Noi Linux下的命令

ctrl+alt+t 进入管理

(啥都别忘了加空格)

(Linux严格区分大小写)

cd /                              根目录

cd-                              主文件

cd ~                            主文件夹

cd Desktop

cd .                          当前目录

cd ..                        上一级文件夹

mkdir node                    创建一个文件夹node

cd/ home/noilinux/Desktop         绝对根目录

ls                   列出当前文件夹下的文件名

rm main.cpp   把main.cpp删除

touch main.cpp   新建main.cpp

mv main.cpp code  把main.cpp移动到code文件夹下

cp main.cpp code复制main.cpp到code文件夹下

2.程序指令

#include<stdio.h>
#define INF 1000000000
int main()
{
 FILE *fin, *fout;
 fin = fopen("data.in", "rb");
 fout = fopen("data.out", "wb");
 int x, n = 0, min = INF, max = -INF, s = 0;
 while(fscanf(fin, "%d", &x) == 1){
  s += x;
  if(x < min) min = x;
  if(x > max) max = x;
  n++;
 }
fprintf(fout, "%d %d %.3f
", min, max, (double)s/n);
fclose(fin);
fclose(fout);
return 0;
}
先声明变量fin和fout(暂且不用考虑FILE *),把scanf改成fscanf,第一个参数为fin;把printf改成fprintf,第一个参数为fout,最后执行fclose,关闭两个文件。
提示2-24:在算法竞赛中,如果不允许使用重定向方式读写数据,应使用fopen和fscanf/fprintf进行输入输出。
重定向和fopen两种方法各有优劣。重定向的方法写起来简单、自然,但是不能同时读写文件和标准输入输出;fopen的写法稍显繁琐,但是灵活性比较大(例如,可以反复打开并读写文件)。顺便说一句,如果想把fopen版的程序改成读写标准输入输出,只需赋值“fin=stdin;fout=stdout;”即可,不要调用fopen和fclose
从多个文件输入
#include<bits/stdc++.h> using namespace std; //#include<window.h> int main() { FILE *fin = fopen("in.txt","r"); FILE *fin2 = fopen("in2.txt","r"); FILE *fout = fopen("out.txt","w"); int n,m; fscanf(fin,"%d",&n); fscanf(fin2,"%d",&m); printf("%d ",n + m); return 0; }

3.对拍

·main程序

(代码一个字都不能改!不然可能出现ukerror  趴.)

#include<bits/stdc++.h>
using namespace std;

void com(string s){
    string t1 = ("g++ " + s + ".cpp -o " + s + ".exe");
    system(t1.c_str());
}
int main(){
    
 while(true){
  com("maker");
  system("maker > in.txt");
  com("eat");
  com("eat2");
  system("eat < in.txt > out.txt");
  system("eat2 < in.txt > ans.txt");
  if(system("fc out.txt ans.txt")){
    break;    
   }
  }
  return 0;
}

 a+b problems的maker

#include<bits/stdc++.h>
using namespace std;
int main()
{
  srand(time(0));
  printf("%d %d
",rand(),rand());
  
}

 补一个看时间的

printf("Time used = %.2f
", (double)clock() / CLOCKS_PER_SEC);
原文地址:https://www.cnblogs.com/phemiku/p/11681358.html