Debug

真不知道为啥博客园的文件更新不上去……

Windows

#include<bits/stdc++.h>
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * debug.h 
 * Author: M
 * Update Date:11/06/19 10:23
 * Description:for debug ,don'to submit cpps with it(you will CE)!!! 
                       For windows
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#define ENDL puts("") 
#define debug cout
#define STOP_1 pause()
#define STOP_2 pause(1000)
#define BIGW system("mode con cols=1000 lines=1000")
#define SMALLW system("mode con cols=80 lines=30")
#define MIDW system("mode con cols=100 lines=100")
#define NL endl
#define TL  "\r"
#define TAB "\t"
#define SP "  "
#define STDLINE "------------------------------------------------------------\n"
#define CTIME atexit(STDTIMEOUT)

using namespace std;
void STDTIMEOUT(){
	const string l(32,'-'); //--------------------------------
	cout<<NL<<l<<NL;
	printf("Finished in %10dms\n",clock());
	
}
string bin(int number,int length_of_out){
	string zeros(length_of_out,'0');
	if(!number)return zeros;
	string number_bin;
	while(number){
		if(number&1)number_bin+='1';
		else number_bin+='0';
		number>>=1;
	}
	while(number_bin.length()<length_of_out)number_bin=number_bin+"0";
	reverse(number_bin.begin(),number_bin.end());
	return number_bin;
}
string bits_27(int number,int length_of_out){
	string zeros(length_of_out,'_');
	if(number==0)return zeros;
	string number_bits_27;
	while(number>0){
		if(number%27==0){
			number_bits_27+=' ';
		}
		else number_bits_27+=number%27+'A'-1;
		number/=27;
	}
	while(number_bits_27.length()<length_of_out)number_bits_27=number_bits_27+'_';
	reverse(number_bits_27.begin(),number_bits_27.end());
	return number_bits_27;
}
inline void pause(){
	while(1);
}
void pause(int time_ms){
	int from_time=clock();
	while(clock()-from_time<=time_ms);
}
void pause(const char* title){
	cout<<title;
	system("pause");
}
bool openfile(string fileout,string filein){
	if(!freopen(filein.c_str(),"r",stdin)){
		cout<<"No file named "+filein<<endl;
		fclose(stdin);
		fclose(stdout);
		return false;
	}
	freopen(fileout.c_str(),"w",stdout);
	return true;
}
bool closefile(){
	if(fclose(stdin)&&fclose(stdout))return 1;
	return 0;
}
template<typename T>
void pour(stack <T> x,int width){
	stack <T> data;
	if(x.empty()){
		cout<<"empty\n";	
	}
	while(!x.empty()){
		int r=x.top();
		cout<<setw(width)<<r;
		x.pop();
	}
}
template <typename Tp>
void savein(string dn,Tp type,string OutTypeN){
	fstream sout;
	sout.open(dn.c_str(),ios_base::out|ios_base::app);
	sout<<OutTypeN<<": "<<type<<endl;
	sout.close();
}
template <typename T>
void pour(vector <T> x,int width,const char *title){
	cout<<title<<":"; 
	T* b=x.begin(),e=x.end();
	for(T* i=b;i<=e;i++){
		cout<<setw(width)<<*i;
	}
}
template <typename Tp>
void pour(Tp Arrayname,int cols_from,int cols_to,int line_from,int line_to,int width,const char *title){
	cout<<title<<"Array[i][j]:\n"<<setw(width)<<"*"<<":";
	for(int i=line_from;i<=line_to;i++)cout<<setw(width)<<i;ENDL;
	for(int i=cols_from;i<=cols_to;i++){
		cout<<setw(width)<<i<<":";
		for(int j=line_from;j<=line_to;j++){
			cout<<setw(width)<<Arrayname[i][j];
		}
		ENDL;
	}
}
string Bot(bool bool_type){
	if(bool_type)return "true";
	return "false";
}
template <typename Tp>
void pour(Tp Array,int from,int to,int width,const char* title){
	cout<<setw(width)<<title<<":";
	for(int i=to;i>=from;i--){
		cout<<setw(width)<<Array[i];
	}
	ENDL;
}
template <typename Tp>
void pour(deque <Tp> _deque,int width,const char *title,const char *_mode){
	cout<<setw(width)<<title<<":";
	try{
		switch(_mode[0]){
			case 'f':
			case 'F':
				if(_deque.empty())
					cout<<"Emtpy";
				else
					while(!_deque.empty()){
						cout<<setw(width)<<_deque.front();
						_deque.pop_front();
					}
				break;
			case 'B':
			case 'b':
				if(_deque.empty())
					cout<<"Emtpy";
				else
					while(!_deque.empty()){
						cout<<setw(width)<<_deque.back();
						_deque.pop_back();
					}
				break;
			default:
				throw "Mode Error\nOnly Have \"Front\" or \"Back\"";
				break;
		}
	}
	catch(const char* exp){
		cout<<"\nTip:"<<exp<<endl;
	}
	ENDL;
}
template<typename Tp>
void pour(queue <Tp> _queue,int width,const char *title){
	cout<<setw(width)<<title<<":";
	if(_queue.empty())
		cout<<"Empty";
	else
		while(!_queue.empty()){
			cout<<setw(width)<<_queue.front();
			_queue.pop();
		}
	ENDL;
}

 Linux

/*
 * debug.h
 *
 * Copyright (C) 2019 - Miemeng
 *
 * debug.h is free; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * debug.h is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with . If not, see <http://www.gnu.org/licenses/>.

----------------------------------------------------------------------

>Before you use it ,you need to know...

 * Name:debug.h 
 * Author: Miemeng
 * Update Date:15/09/19 
 * Description: + For debug ,Don't submit your codes with:
                  -  #include "debug.h" 
                + This is a version for Linux
                + Latest Update
                  - Counters
                  - Some Small Details ;)
                  - Some limits for C++11 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEBUG_H
//For redefination
#define DEBUG_H

#include <bits/stdc++.h>

#define ENDL std::cerr<<std::endl 
#define debug std::cerr
#define STOP_1 pause()
#define STOP_2 pause(1000)
#define NL "\n"
#define TL  "\r"
#define TAB "\t"
#define SP " "
#define CTIME atexit(STDTIMEOUT)
#define name(k) #k
#define Out(k) std::cerr<<name(k)<<":"<<k<<std::endl
#define STDLINE "-----------------------------------------"


/*
	This Namespace contains some var for Debug.
	So you can change them to custom your Codes.
*/
namespace Debug_var{
	std::string True("true"),False("false"),
				leftBracket("("),rightBracket(")");
}

void STDTIMEOUT();
class Warranty_t{
	public:
	Warranty_t(const char* warning){
		std::cerr<<"[WARNING]:"<<warning<<std::endl;
	}
};
/*
	This will remind you of this header.
	So you will not submit your code with it ;)
*/
const Warranty_t Pub_warning("You Are Using The Header \"debug.h\"");
class timer{
	public:
	timer(){
		CTIME;
	}
};
/*
	This is a timer that runs when the program stops.
*/
const timer stdtimer;

class Counter{
	int Count_number;
	std::string Name;
public:
	Counter(const char *st){
		Count_number=0;
		Name=st;
	}
	~Counter(){
		std::cerr<<"[NOTE]:The Counter("\
			<<this->Name\
			<<") Runs "\
			<<std::setw(8)<<this->Count_number\
			<<" times"<<std::endl;
	}
	int operator () (void){
		this->Count_number++;
		return this->Count_number;
	}
};
using namespace std;

/*
	Turn int to string
*/
std::string intstr(int int_var){
	stringstream ss;
	string res;
	ss<<int_var;
	ss>>res;
	return res;
}
/*
	Turn bin int to a string
	for your dp.
*/
std::string int_toseq(int int_var,int minBit,int maxBit){
	std::string str;
	for(int id_1=minBit;id_1<=maxBit;id_1++){
		int id_2=1<<id_1;
		if(int_var&id_2)str+=Debug_var::leftBracket;
		else   str+=SP;
		str+=intstr(id_1);
		if(int_var&id_2)str+=Debug_var::rightBracket;
		else   str+=SP;
	}
	return str;
}
std::string int_toseq(int int_var,int minBit,int maxBit,int _delta_t){
//A version for different beginning
	std::string str;
	for(int id_1=minBit;id_1<=maxBit;id_1++){
		int id_2=1<<(id_1-_delta_t);
		if(int_var&id_2)str+=Debug_var::leftBracket;
		else   str+=SP;
		str+=intstr(id_1);
		if(int_var&id_2)str+=Debug_var::rightBracket;
		else   str+=SP;
	}
	return str;
}
/*
	This function prints
	a increasing number.
*/
void t_counter(){
	static int times=0;
	std::cerr<<"#"
			 <<++times<<"Runs"<<std::endl;
}
/*
	Turn bool to a string .
*/
string Bot(bool bool_type){
	if(bool_type)return Debug_var::True;
	return Debug_var::False;
}
/*
	The time output.
	When you use it,you will get a time output
*/
void STDTIMEOUT(){
	std::cerr<<NL<<STDLINE<<NL;
	std::cerr<<"Runing Time:"<<setw(10)<<clock()/1000.0<<" ms";
	std::cerr<<NL<<STDLINE<<NL;
}
/*
	Return a value you need.
*/
template <typename Tp>
Tp In(Tp &Type){
	std::cin>>Type;
	return Type;
}
#if __cplusplus >= 201103
template <typename Tp=int>
#else 
template <typename Tp>
#endif
Tp getval(){
	Tp k;
	std::cin>>k;
	return k;
}
/*
   Turn a DEC number to BIN
 */
string bin(int number,unsigned int length_of_out){
	string zeros(length_of_out,'0');
	if(!number)return zeros;
	string number_bin;
	while(number){
		if(number&1)number_bin+='1';
		else number_bin+='0';
		number>>=1;
	}
	while(number_bin.length()<length_of_out)number_bin=number_bin+"0";
	reverse(number_bin.begin(),number_bin.end());
	return number_bin;
}
/*
   Pause;
 */
inline void pause(){
	std::cerr<<"Paused"<<std::endl;
	while(1);
}
void pause(int time_ms){
	time_t from_time=clock();
	while(clock()-from_time<=time_ms*1000);
}
/*
   Quick freopen
 */
bool openfile(string filein,string fileout){
	if(!freopen(filein.c_str(),"r",stdin)){
		std::cerr<<"No file named "+filein<<std::endl;
		fclose(stdin);
		fclose(stdout);
		return false;
	}
	freopen(fileout.c_str(),"w",stdout);
	return true;
}
/*
   Quick fclose
 */
bool closefile(){
	if(fclose(stdin)&&fclose(stdout))return 1;
	return 0;
}
/*
   Pours
 */
#if __cplusplus >= 201103

template<typename Tp>
void pour(Tp _type,int width,const char *title){
	std::cerr<<title<<":";
	for(auto _it:_type){
		std::cerr<<setw(width)<<_it;
	}
	ENDL;
}
template<typename Tp,typename Outer>
void pour(Tp _type,Outer _out,const char *title){
	std::cerr<<title<<":";
	for(auto _it:_type){
		_out(_it);
	}
	puts(STDLINE);
}

#endif

template<typename T>
void pour(stack <T> x,int width){
	stack <T> data;
	if(x.empty()){
		std::cerr<<"empty\n";	
	}
	while(!x.empty()){
		int r=x.top();
		std::cerr<<setw(width)<<r;
		x.pop();
	}
}
template <typename Tp>
void savein(string FIle_Name,Tp type,string OutTypeN){
	fstream sout;
	sout.open(FIle_Name.c_str(),ios_base::out|ios_base::app);
	sout<<OutTypeN<<": "<<type<<std::endl;
	sout.close();
}
template <typename Tp>
void pour(Tp Arrayname,int cols_from,int cols_to,int line_from,int line_to,int width,const char *title){
	std::cerr<<title<<"_Array[][]:"<<std::endl<<setw(width)<<"*"<<":";
	for(int id=line_from;id<=line_to;id++)std::cerr<<setw(width)<<id;ENDL;
	for(int id_1=cols_from;id_1<=cols_to;id_1++){
		std::cerr<<setw(width)<<id_1<<":";
		for(int id_2=line_from;id_2<=line_to;id_2++){
			std::cerr<<setw(width)<<Arrayname[id_1][id_2];
		}
		ENDL;
	}
}
template <typename Tp>
void pour(Tp Array,int from,int to,int width,const char* title){
	std::cerr<<setw(width)<<title<<":";
	for(int id=from;id<=to;id++)
		std::cerr<<setw(width)<<Array[id];
	ENDL;
}
template <typename Tp,typename Out_Func>
void pour(Tp Array,int from,int to,Out_Func _out,const char *title){
	std::cerr<<title<<":"<<std::endl;
	for(int id=from;id<=to;id++)
		_out(Array[id]);
	ENDL;
}
template <typename Tp>
void pour(deque <Tp> _deque,int width,const char *title,const char *_mode){
	std::cerr<<setw(width)<<title<<":";
	try{
		switch(_mode[0]){
			case 'f':
			case 'F':
				if(_deque.empty())
					std::cerr<<"Emtpy";
				else
					while(!_deque.empty()){
						std::cerr<<setw(width)<<_deque.front();
						_deque.pop_front();
					}
				break;
			case 'B':
			case 'b':
				if(_deque.empty())
					std::cerr<<"Emtpy";
				else
					while(!_deque.empty()){
						std::cerr<<setw(width)<<_deque.back();
						_deque.pop_back();
					}
				break;
			default:
				throw "Mode Error\nOnly Have \"Front\" or \"Back\"";
				break;
		}
	}
	catch(const char* exp){
		std::cerr<<"\n[ERROR]:"<<exp<<std::endl;
	}
	ENDL;
}
template<typename Tp>
void pour(queue <Tp> _queue,int width,const char *title){
	std::cerr<<setw(width)<<title<<":";
	if(_queue.empty())
		std::cerr<<"Empty";
	else
		while(!_queue.empty()){
			std::cerr<<setw(width)<<_queue.front();
			_queue.pop();
		}
	ENDL;
}

#endif

 

posted @ 2019-10-20 18:40  Miemeng_麦蒙  阅读(183)  评论(0编辑  收藏  举报

小麦在雨中,蒙蒙的雾气

麦蒙不想有人骚扰他,如果有必要 联系 QQ:1755601414

如果你嫌广告大,那就喷我吧,不是博客园的锅。