⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit2.h

📁 it will work it is recogntion code only
💻 H
📖 第 1 页 / 共 3 页
字号:
//**********************************************************
//Copyright(c)2004  Alexander Kadyrov
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <memory.h> //for memcpy
#include <complex> //for complex numbers

#define DIRSLASH "/" 
#define EQ ==

double pi=3.1415926535, pi2=2*pi, pi1=1/pi;

#include <algorithm>//for sort of C++
int*sortCpp(int*A,int LA,int*sorttemp)
  {for(int j=LA-1;j>=0;j--)sorttemp[j]=A[j];
   using namespace std; sort(sorttemp,sorttemp+LA);return sorttemp;}

//%%%%%%%%%%%%%%%%%%%%%%% Time controll:
#include <time.h> 
clock_t StartTime;int tictocLabel;
void tic(int ticLabel){tictocLabel=ticLabel;StartTime=clock();};
double toc(int tocLabel)
    {if (tocLabel!=tictocLabel) 
         printf("???label for tic was differnt: tic=%d  and toc=%d;\n",tictocLabel,tocLabel);
     return double(clock()-StartTime)/CLOCKS_PER_SEC;};
void Toc(int tocLabel)
    {double d= double(clock()-StartTime)/CLOCKS_PER_SEC;
     if (tocLabel!=tictocLabel) 
         printf("???label for tic was differnt: tic=%d  and toc=%d;\n",tictocLabel,tocLabel);
printf(" elasped time %d ms (tictoc lable=%d)\n",long (d*1000),tictocLabel);}//END.
void Toc(int tocLabel,char *s)
    {double d= double(clock()-StartTime)/CLOCKS_PER_SEC;
     if (tocLabel!=tictocLabel) 
         printf("???label for tic was differnt: tic=%d  and toc=%d;\n",tictocLabel,tocLabel);
printf(" %s : Elasped time %d ms (tictoc lable=%d)\n",s,long (d*1000),tictocLabel);}//END.

	 //%%%%%%%%%%%%%%%%%%%%%%% Collecting time segments:
clock_t timer001=0,timer002=0,timer003=0,timer004=0;
double sumTime001=0,sumTime002=0,sumTime003=0,sumTime004=0;

void timer1start(){sumTime001=0;timer001=clock();};
void timer1restart(){timer001=clock();};
void timer1pause(){sumTime001+=double(clock()-timer001)/CLOCKS_PER_SEC;};
double timer1result(){sumTime001+=double(clock()-timer001)/CLOCKS_PER_SEC;return sumTime001;};
void Timer1result(){sumTime001+=double(clock()-timer001)/CLOCKS_PER_SEC;
                      printf(" Timer1result=%d ms\n",int (sumTime001*1000));}
void Timer1result(char*s){sumTime001+=double(clock()-timer001)/CLOCKS_PER_SEC;
                      printf(" Timer1result=%d ms  (for %s)  \n ",int (sumTime001*1000),s);}
  


void timer2start(){sumTime002=0;timer002=clock();};
void timer2restart(){timer002=clock();};
void timer2pause(){sumTime002+=double(clock()-timer002)/CLOCKS_PER_SEC;};
double timer2result(){sumTime002+=double(clock()-timer002)/CLOCKS_PER_SEC;return sumTime002;};
void Timer2result(){sumTime002+=double(clock()-timer002)/CLOCKS_PER_SEC;
                        printf(" Timer2result=%d ms\n",int (sumTime002*1000));}
void Timer2result(char*s){sumTime002+=double(clock()-timer002)/CLOCKS_PER_SEC;
                      printf(" Timer2result=%d ms  (for %s)  \n ",int (sumTime002*1000),s);}


//%%%%%%%%%%%%%%%%%%%%%%% STRINGS AND FILES
char *concat(char*a,char*b)
    {int i=0; while (a[i]) i++; int j=0; while (b[j]) j++; 
     int d=i+j+1; // now i and j are lengths without\0
     char *c; c=new char[d]; 
     int k; for(k=0;k<i;k++) c[k]=a[k];
     int l; for(l=i;l<=i+j;l++) c[l]=b[l-i];
     return(c);
    };//END concat
char*composeFullName(char*dir,char*filename)
{char*fullname,*temp;
 if (dir[0]) 
     {temp=concat(dir,DIRSLASH);
      fullname=concat(temp,filename);} 
 else fullname=filename; return fullname; 
};//end composeFullName
int strCompare(char*a,char*b)
    {int i=0; while (a[i]) i++; 
     int j=0; while (b[j]) j++;
     int k;
     if (i != j) return 0; 
        else
         for(k=0; k<i; k++) 
             if (a[k] != b[k]) return 0;
      return 1;
     };//END strCompare
char *getExtension(char*a)
    {int i=0; while (a[i]) i++; 
     int j;
     for(j=0; j<i; j++) 
         if (
             a[j] == '.') break;
     if (j>=i-1) return ""; //no extension
     char *c; c=new char[i-j+1]; 

     int k; for(k=j+1;k<=i;k++) c[k-j-1]=a[k];
     return(c);    
};//END getExtension
char *changeExtention(char*a,char*newExt)
    {int i=0; while (a[i]) i++;
     int j; 
     for(j=0; j<i; j++) 
         if (a[j] == '.') break;
     
     char *c;  //extension<10
     if (a[j] != '.') 
         { c=concat(a,"."); return concat(c,newExt);
         };
     c=new char[j+10]; int k;
     for(k=0;k<=j;k++) c[k]=a[k];
     k=j;
     do {k++;c[k]=newExt[k-j-1];} while (newExt[k-j-1]);
     return c;//concat("",c);
         };//END changeExtention
char *removeExtention(char*a)
    {int i=0; while (a[i]) i++;
     int j; 
     for(j=0; j<i; j++) 
         if (a[j] == '.') break;
     
     char *c;  //extension<10
     if (a[j] != '.') 
         { c=concat(a,""); return c;
         };
     c=new char[j]; int k;
     for(k=0;k<j;k++) c[k]=a[k]; c[j]=a[i];
     return c;
     };//END removeExtention

void fputsM(char*cs,FILE *stream)
  	{ int i=0;
	  while(
          fputc(cs[i],stream),
          cs[i]) 
          i++;
	};//END fputsM

char* fgetsM(int n,FILE *stream)
	{char*cs,*in; in=new char[n]; char c; int i=0,j;
	 while(in[i]=c=fgetc(stream),c) i++;
	 cs=new char[i+1];
	 for (j=0;j<=i;j++)cs[j]=in[j]; delete[]in;
	 return (cs);
	};//END fgetsM
//%%%%%%%%%%%%%%%%%%%%%%% Simple math
#define ROUND(a) floor(a+0.5)
static int round(double a)
{return int(floor(a+0.5));}

static double roundD(double a)
{return floor(a+0.5);}

#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a<b)?a:b
static double maxD(double a, double b)
{return ((a>b)?a:b);}
static int maxI(int a, int b)
{return ((a>b)?a:b);}
static double minD(double a, double b)
{return ((a<b)?a:b);}
static int minI(int a, int b)
{return ((a<b)?a:b);}
void swap(double *a,double *b)
{static double c;c=*a;*a=*b;*b=c;}
void swap(int *a,int *b)
{static int c;c=*a;*a=*b;*b=c;}
double const log_12=1./log(2.);double const log_2=log(2.);
void packdouble(double a,unsigned char*ss,unsigned char*k,unsigned char*u,unsigned char*v)
{ //works for Unix and Microsoft
  if (a EQ 0) {*ss=4; *k=0; *u=0; *v=0; return;}
  if (a > 0) *ss=1; else {*ss=0; a=-a;}
  double K=log(a)*log_12; int fK= int (floor(K)); 
  if (K>=0) *ss=*ss+2; *k=abs(fK);
  int r= round((exp((K-fK)*log_2)-1)*(1<<16));
  *u= r >> 8;
  *v= r-(int(*u) << 8);  
}//END.
double unpackdouble(unsigned char ss,unsigned char k,unsigned char u,unsigned char v)
{ if (ss & 4) return (0.0);
  double P= 1 << k; if (!(ss & 2)) P=1.0/P;
  double m=((int(u) << 8) + v ) / double( 1<<16) +1 ;
  if (!(ss & 1)) m=-m;
  return (m*P);
}//END.

double spline4(double x,double c_1,double c0,double c1,double c2)
{
// f'(0) = 0.5*(c1-c_1); f'(1)=0.5*(c2-c0)
// f(0)=c0; f(1)=c1;
// find f(x)=a+b*x+c*x^2+d*x^3
double b,a,u,v,d,c,fx;
b=0.5*(c1-c_1); a= c0;
u=0.5*(c2-c0)-b; v=c1-a-b;
d=u-2*v;c=-(u-3*v);

fx= (d*x+c)*x+b; fx=fx*x+a; return(fx);
}//END.
//__________________END simple math


//%%%%%%%%%%%%%%%%%%%%%%% Simple printing:
//PN prints new line, PV prints a variable, PA prints array,PAUSE makes pause,
#define PN myprint(); 
#define PS(a)    myprint(a);
#define PSN(a)   {myprint(a);myprint();}
#define NPS(a)   {myprint();myprint(a);}
#define NPSN(a)  {myprint();myprint(a);myprint();}
#define PV(a)    myprint(#a,a);   
#define PVN(a)   {myprint(#a,a);myprint();}
#define NPV(a)   {myprint();myprint(#a,a);}
#define NPVN(a)  {myprint();myprint(#a,a);myprint();}
#define PA(a,start,finish)           myprint(#a,a,start,finish);
#define PC(a,d,h)                    myprintCirc(#a,a,d,h);
#define P2D(a,xlength,ylength,space) myprint(#a,a,xlength,ylength,space);
#define PAU PAUSE();

void myprint() {printf("\n");};
void myprint(char *a){printf(" %s;",a);};
void myprint(char *s,char *a){printf(" char*%s='%s';",s,a);};
void myprint(char *s,int a){printf(" int %s= %d;",s,a);};
void myprint(char *s,unsigned char a){printf(" unchar %s= %d;",s,a);};
void myprint(char *s,float a){printf(" float %s= %f;",s,a);};
void myprint(char *s,double a){printf(" double %s= %f;",s,a);};
void myprint(char *s,long double a){printf(" long double %s= %Lf;",s,a);};
void myprint(char *s,unsigned int a){printf(" unsigned int %s= %d;",s,a);};
void myprint(char *s,std::complex<int> a){printf(" complex<int> %s= %d%+di ;",s,
                            std::real(a),std::imag(a));};
void myprint(char *s,std::complex<double> a){printf(" complex<double> %s= %f%+fi ;",s,
                            std::real(a),std::imag(a));};
void myprint(char *s,std::complex<char> a){printf(" complex<char> %s= %d%+di ;",s,
                            std::real(a),std::imag(a));};
void myprint(char *s,std::complex<unsigned char> a){printf(" complex<unsigned char> %s= %d%+di ;",s,
                            std::real(a),std::imag(a));};
void myprint(char *s,std::complex<float> a){printf(" complex<float> %s= %f%+fi ;",s,
                            std::real(a),std::imag(a));};

char fdbnfBf;
//void PAUSE(){printf(" ..PAUSE, press <Enter> to continue..");};

void PAUSE(){printf(" ..PAUSE, press <Enter> to continue..");
    scanf("%c", &fdbnfBf);};

void PAUSE(char*s){printf("%s",s);PAUSE();};

void myprint(char *s,int* a,int start,int finish)
    {printf(" arr int %s",s); int i;
  for(i=start;i<=finish;i++) printf("[%d]=%d ",i,a[i]);
            printf("\n");};
void myprint(char *s,unsigned char* a,int start,int finish)
    {printf(" arr int %s",s); int i;
  for(i=start;i<=finish;i++) printf("[%d]=%d ",i,a[i]);
            printf("\n");};
void myprint(char *s,float* a,int start,int finish)
    {printf(" arr float %s",s); int i;
  for(i=start;i<=finish;i++) printf("[%d]=%f ",i,a[i]);
            printf("\n");};
void myprint(char *s,double* a,int start,int finish)
    {printf(" arr double %s",s); int i;
  for(i=start;i<=finish;i++) printf("[%d]=%g ",i,a[i]);
            printf("\n");};
void myprint(char *s,int* a,
             int xlength,int ylength,int spaceForElement)
    { int var;
    int vol=xlength*ylength;int i,max;
    printf(" arr2D int %s[lenx=%d,leny=%d]",
                          s,xlength,ylength);
    if (spaceForElement==1)
        { max=a[0]; for (i=1;i<vol;i++)
                        if (max<a[i]) max=a[i];
          printf(" max= %d",max);PAUSE();
        };if (max==0) max++;
    printf("\n");
    for (i=0;i<vol;i++)
        {if ((spaceForElement==1)&&(max>=10)) 
        var=int(floor(9.99*a[i]/max));
                else var=a[i];
         if (spaceForElement==1)    
         printf("%d",var); else 
         if (spaceForElement==2) 
         printf("%2d",var); else 
         if (spaceForElement==3) 
         printf("%3d",var); else
         if (spaceForElement==4)
         printf("%4d",var); else printf("%d",var);
         if (((i+1) % xlength)==0) printf("\n");
//         if (((i+1) % (xlength*15))==0) PAUSE();
        }
    };
void myprint(char *s,double* a,
             int xlength,int ylength,int spaceForElement)
    { int var;
    int vol=xlength*ylength;int i;double max,min;
    printf(" arr2D int %s[lenx=%d,leny=%d]",
                          s,xlength,ylength);
        { max=a[0]; for (i=1;i<vol;i++)
                        if (max<a[i]) max=a[i];
          printf(" max= %f",max);
        };
        { min=a[0]; for (i=1;i<vol;i++)
                        if (min>a[i]) min=a[i];
          printf(" min= %f",min);
        };if (min EQ max) max++;
    printf("\n");
    for (i=0;i<vol;i++)
        { 
        var=int(floor(9.99*(a[i]-min)/(max-min)));
         if (spaceForElement==1)    
         printf("%d",var); else 
         if (spaceForElement==2) 
         printf("%2d",var); else 
         if (spaceForElement==3) 
         printf("%3d",var); else
         if (spaceForElement==4)
         printf("%4d",var); else printf("%d",var);
         if (((i+1) % xlength)==0) printf("\n");
//         if (((i+1) % (xlength*15))==0) PAUSE();
        }
    };

void myprintCirc(char *s,float* a,int dim,int h)
    {int i; float max=a[0], min=a[0];
     for(i=1;i<dim;i++) 
         {if (max<a[i]) max=a[i];
          if (a[i]<min) min=a[i];
         };//end for i
     if (min EQ max) max++;
     int j, **lattice=new int*[h];
     for (j=0;j<h;j++)
         {lattice[j]=new int[dim];
          for(i=0;i<dim;i++) (lattice[j])[i]=0;
         }//end for j
     for(i=0;i<dim;i++)
      (lattice[round((h-1)*(a[i]-min)/(max-min))])[i]=1;
//!!     printf("____circus_%s___min=_%f__max=%f___dim=%d_____\n",
//!!                                        s,min,max,dim);
     for (j=h-1;j>=0;j--)
         {for(i=0;i<dim;i++) 
         if ((lattice[j])[i]) {printf("*");} else printf(" ");
            printf("\n");
         };//end for j
     printf("----circus %s   min= %f  max=%f   dim=%d ---- :\n",
                                        s,min,max,dim);
     for (j=0;j<h;j++) delete[] (lattice[j]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -