现在的位置: 首页 > 综合 > 正文

个人最新使用的代码模板和自用debug头文件

2013年04月28日 ⁄ 综合 ⁄ 共 3083字 ⁄ 字号 评论关闭

首先不得不说,成都打铁太伤感了,从银牌区,到铜牌区,再到打铁区=。=

尤其是,一直被我们压着打的对面的队伍最后四道题,然后我们那个时候在纠结谁的J题打的是正确的=。=

所以不得不说,这个游戏还是需要一些策略的。。。

好了,不谈这个了,这几天也没什么心情接着撸题目,整理了自己十分混乱的自用模板和自己用的debug头文件。希望有人可以用到。

Common Code for each Cpp

/****
	*@PoloShen
	*Title:
	*/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#include <vector>
#include <list>
#include <stack>
#include <deque>
#include <queue>

#define DBG 0
#define ALG 0
#define USING_STL_STRING	1
#define USING_STL_VECTOR	1
#define USING_STL_LIST		1
#define USING_STL_STACK		1
#define USING_STL_DEQUE		1
#define USING_STL_QUEUE		1

#if DBG
	#include "debug.h"
#else
	#define __DBG 0 &&
#endif // DBG

#if ALG
	#include <algorithm>
#else
	#ifndef min
		#define min(x,y) ((x) < (y) ? (x) : (y))
	#endif
	#ifndef max
		#define max(x,y) ((x) > (y) ? (x) : (y))
	#endif
#endif // ALG

int main(){
	__DBG cout<<"test for outputing."<<endl;
	cout<<"test end."<<endl;
    return 0;
}

Debug.h

///#ifndef DEBUG_H_INCLUDED
///#define DEBUG_H_INCLUDED

#ifndef DBG
	#define DBG 1
#endif // DBG

#ifndef USING_STL_STRING
	#define USING_STL_STRING	1
#endif // USING_STL_STRING

#ifndef USING_STL_VECTOR
	#define USING_STL_VECTOR	1
#endif // USING_STL_VECTOR

#ifndef USING_STL_LIST
	#define USING_STL_LIST		1
#endif // USING_STL_LIST

#ifndef USING_STL_STACK
	#define USING_STL_STACK		1
#endif // USING_STL_STRING

#ifndef USING_STL_DEQUE
	#define USING_STL_DEQUE		1
#endif // USING_STL_DEQUE

#ifndef USING_STL_QUEUE
	#define USING_STL_QUEUE		1
#endif // USING_STL_QUEUE

/*
*For each debug functions and statements,
*use them with extern "__DBG"
*/

#if DBG
	#include <iostream>
	#include <cstdio>
	#include <cstdlib>

	#define __DBG

	//Should use with __DBG
	#define dout cout<<"--->"<<__LINE__<<">\t"
	#define ShowLine dout<<endl
	#define pause system("pause")

	//Shall use without __DBG
	#define write(x) #x" = "<<(x)<<" "
	#define awrite(array,num) #array"["<<num<<"]="<<array[num]<<" "
#endif // DBG

class Debugging{
public:
	//to test for an empty array
	template <typename T>bool _arr_empty(T a[], int _array_size, int _array_0 = 0){
		bool flag = 1;
		int st = _array_0, ed = _array_size;
		for (int i = st ; i < ed; i++){
			if (a[i]){
				flag = 0;break;
			}
		}
		return flag;
	}
	//to print an array
	template <typename T>void _arr_print(T a[], int _array_size, int _array_0 = 0){
		cout<<"On printing this array."<<endl;
		int sz = _array_size, j = 1;
		for (int i = _array_0; i < sz; i++, j++){
			cout<<awrite(a,i)<<" ";
			if (j % 6 == 0)cout<<endl;
		}
		cout<<"\n|< End Of Array >|\n"<<endl;
		return;
	}

	#if USING_STL_STRING
		//to print a string which is STL-typed
		void _str_print(string s){
			cout<<"On printing this string which is STL-typed."<<endl;
			string::size_type sz=s.size();
			for (int i = 0; i < sz; i++){
				printf("%c",s[i]);
			}
			puts("|< EOL >|\n\n");
			return;
		}
	#endif // USING_STL_STRING

	#if USING_STL_LIST
		//to print a list with any type
		template <typename T>void _lst_print(list<T> l){
			cout<<"On printing this list."<<endl;
			if (l.empty()){
				cout<<"List is empty.";
				cout<<"\n|< End Of List >|\n"<<endl;
			}
			else {
				list<T> ltmp=l;
				int sz=l.size();
				for (int i = 0; i < sz; i++){
					cout<<ltmp.front()<<" ";
					ltmp.pop_front();
				}
				cout<<"\n|< End Of List >|\n"<<endl;
			}
		}
	#endif

	#if USING_STL_VECTOR
		//to print a vector with any type
		template <typename T>void _vec_print(vector<T> v){
			cout<<"On printing this vector."<<endl;
			int sz=v.size();
			for (int i = 0; i < sz; i++){
				cout<<awrite(v,i)<<" ";
			}
			cout<<"\n|< End Of Vector >|\n"<<endl;
		}
	#endif // USING_STL_VECTOR

}__dbg;

///#endif // DEBUG_H_INCLUDED

抱歉!评论已关闭.