zoukankan      html  css  js  c++  java
  • acm的一些头文件和调试代码

      个人觉得单步调试麻烦且费时间,所以我两年时间里F4+watch基本没怎么用过,但由于"查看变量的值"这个需求总是存在的,并且调试时通常需要显示很多东西,printf写起来又比较蛋疼,恰巧在c++11上知道了可变参数模板这个新的东西,于是果断拿过来写debug代码了。

    本地调试时用的,写在头文件里,然后只在本地包含它,OJ上忽略。[local.h] =>

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    #ifndef _local
    #define _local
    namespace Debug {
        void print() {
            cout << endl;
        }
        template<typename T>
        void print(const T t) {
            cout << t << endl;
        }
        template<typename F, typename...R>
        void print(const F f, const R...r) {
            cout << f << " ";
            print(r...);
        }
        template<typename T>
        void print(T*p, T*q) {
            int d = p < q ? 1 : -1;
            while(p != q) {
                cout << *p << ", ";
                p += d;
            }
            cout << endl;
        }
        template<typename T1, typename T2>
        void print(pair<T1, T2> x) {
            print("first = "", x.first, "" second = "", x.second, """);
        }
    }
    
    class Timer {
    private:
        clock_t _start;
        clock_t _end;
    
    public:
        Timer() { start(); }
        void start() {
            _start = clock();
        }
        double get() {
            _end = clock();
            double usedtime = double(_end - _start) / CLK_TCK;
            cout << "used time: " <<  usedtime << " s
    ";
            return usedtime;
        }
    };
    
    #endif
    

    头文件等=>

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    #include <bits/stdc++.h>
    using namespace std;
    #ifndef ONLINE_JUDGE
        #include "local.h"
    #endif
    #define X first
    #define Y second
    #define pb(x) push_back(x)
    #define mp(x, y) make_pair(x, y)
    #define all(a) (a).begin(), (a).end()
    #define mset(a, x) memset(a, x, sizeof(a))
    #define mcpy(a, b) memcpy(a, b, sizeof(a))
    typedef long long ll;
    template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
    template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif // ONLINE_JUDGE
    
        return 0;
    }
    

    结果:

  • 相关阅读:
    用C#实现宽带重新拨号
    CALLBACK FUNCTION 回调函数
    编译程序 VS 解释程序
    《围城》读书笔记
    鼠标点击器
    工作与找工作的日子
    Windows 7下VS2003的查找无响应问题
    收藏几句关于程序的名言
    static知识小结
    如何定义和实现一个类的成员函数为回调函数(转)
  • 原文地址:https://www.cnblogs.com/jklongint/p/4822825.html
Copyright © 2011-2022 走看看