基础技术

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\n", 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",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\n",rand(),rand());
  
}

 补一个看时间的

printf("Time used = %.2f\n", (double)clock() / CLOCKS_PER_SEC);

 

posted @ 2019-10-15 21:55  QUEKI嶺冬  阅读(159)  评论(0)    收藏  举报
/*! Color themes for Google Code Prettify | MIT License | github.com/jmblog/color-themes-for-google-code-prettify */ .pln{color:#4d4d4c}ol.linenums{margin-top:0;margin-bottom:0;color:#8e908c}li.L0,li.L1,li.L2,li.L3,li.L4,li.L5,li.L6,li.L7,li.L8,li.L9{padding-left:1em;background-color:#fff;list-style-type:decimal!important;}@media screen{.str{color:#718c00}.kwd{color:#8959a8}.com{color:#8e908c}.typ{color:#4271ae}.lit{color:#f5871f}.pun{color:#4d4d4c}.opn{color:#4d4d4c}.clo{color:#4d4d4c}.tag{color:#c82829}.atn{color:#f5871f}.atv{color:#3e999f}.dec{color:#f5871f}.var{color:#c82829}.fun{color:#4271ae}} /*下面是我设置背景色,字体大小和字体*/ .cnblogs-markdown code{ background:#fff!important; } .cnblogs_code,.cnblogs_code span,.cnblogs-markdown .hljs{ font-size:16px!important; } .syntaxhighlighter a, .syntaxhighlighter div, .syntaxhighlighter code, .syntaxhighlighter table, .syntaxhighlighter table td, .syntaxhighlighter table tr, .syntaxhighlighter table tbody, .syntaxhighlighter table thead, .syntaxhighlighter table caption, .syntaxhighlighter textarea { font-size: 16px!important; } .cnblogs_code, .cnblogs_code span, .cnblogs-markdown .hljs{ font-family:consolas, "Source Code Pro", monaco, monospace !important; } //以上是代码高亮 /* 文字特效 */