add numerical recipes library
This commit is contained in:
26
lib/nr/cpp/recipes/decchk.cpp
Normal file
26
lib/nr/cpp/recipes/decchk.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "nr.h"
|
||||
|
||||
bool NR::decchk(string str, char &ch)
|
||||
{
|
||||
char c;
|
||||
int j,k=0,m=0;
|
||||
static int ip[10][8]={{0,1,5,8,9,4,2,7},{1,5,8,9,4,2,7,0},
|
||||
{2,7,0,1,5,8,9,4},{3,6,3,6,3,6,3,6},{4,2,7,0,1,5,8,9},
|
||||
{5,8,9,4,2,7,0,1},{6,3,6,3,6,3,6,3},{7,0,1,5,8,9,4,2},
|
||||
{8,9,4,2,7,0,1,5},{9,4,2,7,0,1,5,8}};
|
||||
static int ij[10][10]={{0,1,2,3,4,5,6,7,8,9},{1,2,3,4,0,6,7,8,9,5},
|
||||
{2,3,4,0,1,7,8,9,5,6},{3,4,0,1,2,8,9,5,6,7},{4,0,1,2,3,9,5,6,7,8},
|
||||
{5,9,8,7,6,0,4,3,2,1},{6,5,9,8,7,1,0,4,3,2},{7,6,5,9,8,2,1,0,4,3},
|
||||
{8,7,6,5,9,3,2,1,0,4},{9,8,7,6,5,4,3,2,1,0}};
|
||||
|
||||
int n=str.length();
|
||||
for (j=0;j<n;j++) {
|
||||
c=str[j];
|
||||
if (c >= 48 && c <= 57)
|
||||
k=ij[k][ip[(c+2) % 10][7 & m++]];
|
||||
}
|
||||
for (j=0;j<10;j++)
|
||||
if (ij[k][ip[j][m & 7]] == 0) break;
|
||||
ch=char(j+48);
|
||||
return k==0;
|
||||
}
|
||||
Reference in New Issue
Block a user