Linux

来源:互联网 发布:com域名与cn域名 编辑:程序博客网 时间:2024/06/10 04:54

开始试着用Linux了


不过没用NOI-Linux,主要以前装过,但是不能加源,版本也很低


ubuntu最新版又不敢装,听说有些大神把以前的硬盘都装得格式化了,资料全无


所以就用的 LinuxDeepin ,是深度的,其实还有一个 StartOS ,是 YLMF 的,不过好像深度的Linux口碑稍好,所以就装的 LinuxDeepin


用了一天了,感觉还可以,尤其喜欢那个深度软件中心,不用自己google了


唯一不爽的就是测试,好在网上有大神用shell编出了一个类似cena的测试工具,代码如下

#!/bin/bash # The script is only for C++ source# Please use freopen to I/O# Write down the directory of the test data in file PathFile, "Orz" is defined.# It can't tell RE from WA, so it's up to you. (if you know how to solve this problem, please tell me, thank you.)# There must be some grammer errors in these sentence, just ignore it! #Prepare for all NamePathFile="Orz"TmpName='jkjkjkjkjkjkjkjkjkjk' #you can change this but you should make sure that there no filename conflictProgName=$1DataDir=`cat ${PathFile}`TimeLimit=5 #Change this for change time limit (unit : seconds) Suffix=`echo ${ProgName} | sed -e 's/.*\.\(.*$\)/\1/'`InputName=`sed -n 's/freopen\s*(\s*"\(.*\)"\s*,\s*"r".*$/\1/p' ${1}`OutputName=`sed -n 's/freopen\s*(\s*"\(.*\)"\s*,\s*"w".*$/\1/p' ${1}` #CompileFlag_cpp="g++ -o2 ${ProgName} -o ${TmpName} -pg"Compile_Success=0 if [ "${Suffix}" = "cpp" ]; then        $Flag_cpp        if [ "$?" = 0 ] ; then Compile_Success=1; fifi #Fail to Compileif [ "${Compile_Success}" = 0 ]then        echo "Compile Error"        exitfi #Test...Total_Time=0Total=0cnt=0input_list=$(find ${DataDir} -regex '.*\.in[.0-9]*') echo "-------------------------------------------------------------------"for i in ${input_list}; do        cp ${i} ${InputName}        usetime=`{ time timeout ${TimeLimit} ./${TmpName}; } 2>&1 | grep real | sed 's/real\s//g'`        min=`echo ${usetime} | sed 's/\([^m]*\).*/\1/g'`        sec=`echo ${usetime} | sed 's/.*m\([^s]*\).*/\1/g'`        used_time=`python -c "print int(${min}*60*1000+${sec}*1000)"`         #check tle        msLimit=`expr $TimeLimit \* 1000`        if [ $used_time -ge $msLimit ]; then                TLE=1        else                TLE=0        fi                for j in {"out","ans","ou"}; do                output_file=`echo ${i} | sed -e "s/\.in/\.${j}/g"`                if [ -e ${output_file} ]; then                        if [ "${j#.*}" != "in" ]; then                                diff -b ${output_file} ${OutputName} -q > vani_log                                if [ $? -eq 0 ]; then Status="Accepted"                                        else Status="Wrong Answer"                                fi                        fi                fi        done        let cnt=${cnt}+1         if [ $TLE = "1" ]; then                Status="Time Limit Exeeceded"                if [ ${cnt} -le 9 ]; then                        echo "Test Case  ${cnt} :  ${Status}    Time: ${used_time} ms"                else                        echo "Test Case ${cnt} :  ${Status}     Time: ${used_time} ms"                fi        else                 if [ ${cnt} -le 9 ]; then                        echo "Test Case  ${cnt} :  ${Status}            Time: ${used_time} ms"                else                        echo "Test Case ${cnt} :  ${Status}             Time: ${used_time} ms"                fi        fi        if [ "$Status" = "Accepted" ]        then                 Total=`expr $Total + 1`        fi        Total_Time=`expr $Total_Time + $used_time`done if [ -e ${InputName} ]; then         sudo rm ${InputName} fiif [ -e ${OutputName} ]; then         sudo rm ${OutputName} fiif [ -e ${TmpName} ]; then        sudo rm ${TmpName}fi echo "-------------------------------------------------------------------"echo "Total used time: $Total_Time ms"echo "Total case(s): $cnt"echo "Accepted case(s): $Total"echo "Done"

把它保存成 .sh ,然后同目录下新建一个 Orz (没有后缀),里面写入你的测试数据的目录

然后把你要测试的源代码拷如同目录,给 .sh 加上运行权限,sudo 运行就 ok

很方便的是不需要配置输入输出那些,它会从你的源代码中的freopen中提取(所以好像只能是C/C++的。。。。)



感觉很好,截个图



感谢网友提出bug,其实是我自己忘说了^0^

在终端里面路径对了后加上运行权限(假设为T.sh)

sudo chmod +x T.sh

然后在运行,后面要加上你的源代码文件名(假设为test.cpp)

sudo ./T.sh test.cpp


实在不好意思啦,博客已更新




原创粉丝点击