public.cpp

来自「通信BOSS计费方面的服务器源码,有很多经典的创意,值得借鉴,在UNIX上运行.」· C++ 代码 · 共 1,271 行 · 第 1/2 页

CPP
1,271
字号
		number=-number;

        qxf_flag=1;

	}



	inistr = fcvt(number, 2, (int* const)&pointpos, (int* const)&sign);

	

	if(sign != 0 || pointpos < -1)

	{

		printf("错误-输入数值为负或太小!\n");

		strcpy(outstr, "");

		exit(1);

	}

	length = strlen(inistr);



	if(cntype == 0)

	{

		if(pointpos > 17)

		{

			printf("错误-转换为人民币大写的数字整数位数最大17位!\n");

			strcpy(outstr, "");

			exit(2);

		}

	}

	//输入值为浮点数(整数已加上.00)

	if(pointpos >= 0)									

	{

		if(pointpos > 0)

			MidOfStr(str1, inistr, 0, pointpos);	//取整数部分

		else 

			strcpy(str1, "0");

		MidOfStr(str2, inistr, pointpos, 2);		//取小数部分

	}

	else 

	{

		strcpy(str1, "0");

		MidOfStr(strtemp, inistr, 0, 1);

		strcpy(str2, "0");

		strcat(str2, strtemp);

	}



	if(atoi(str2) == 0)								//如果小数部分为0,则取消小数部分的分析

	{

		strcpy(str2, "");

	}



//*****分析转换整数部分*****



	intlen = strlen(str1);	

	if(intlen > 8)									//分析整数部分在100000000以上的

	{

		//按每4位为一段拆分成三段,逐段分析		

		MidOfStr(num[1], str1, 0, intlen-8);

		MidOfStr(num[2], str1, intlen-8, 4);

		MidOfStr(num[3], str1, intlen-4, 4);

				

		DigitalToCapital(atoi(num[1]), 1, firstout);

		strcpy(number1, firstout);

		strcat(number1, "亿");						//若干亿

		

		MidOfStr(temp8, num[2], 0, 1);

		if(strncmp(temp8, "0", 1) == 0)				//分析千万位

		{

			strcpy(n[1], numstr[1]);				//若该位为0,则数位赋值“零”

		}

		else

		{

			strcpy(n[1], numstr[atoi(temp8)+1]);

			strcat(n[1], "仟");

		}



		MidOfStr(temp7, num[2], 1, 1);

		if(strncmp(temp7, "0", 1) == 0)				//分析百万位

		{

			if(strncmp(temp8, "0", 1) == 0)

			{

				strcpy(n[2], "");					//若千万位为0,则该位为空

			}

			else

			{

				strcpy(n[2], numstr[1]);

			}

		}

		else

		{

			strcpy(n[2], numstr[atoi(temp7)+1]);

			strcat(n[2], "佰");

		}



		MidOfStr(temp6, num[2], 2, 1);

		if(strncmp(temp6, "0", 1) == 0)				//分析十万位

		{

			if (strncmp(temp7, "0", 1) == 0)

			{

				strcpy(n[3], "");

			}

			else

			{

				strcpy(n[3], numstr[1]);

			}

		}

		else

		{

			strcpy(n[3], numstr[atoi(temp6)+1]);

			strcat(n[3], "拾");

		}



		MidOfStr(temp5, num[2], 3, 1);

		if(strncmp(temp5, "0", 1) == 0)				//分析万位

		{

			strcpy(n[4], "");

		}

		else

		{

			strcpy(n[4], numstr[atoi(temp5)+1]);

		}

		

		MidOfStr(strtemp, num[2], strlen(num[2])-3, 3);

		if(strncmp(strtemp, "000", 3) == 0)			//当末尾有000时

		{

			strcpy(n[2], "");

			strcpy(n[3], "");

			strcpy(n[4], "");

		}



		MidOfStr(strtemp, num[2], strlen(num[2])-2, 2);

		if(strncmp(strtemp, "00", 2) == 0)			//当末尾有00时

		{

			strcpy(n[3], "");

			strcpy(n[4], "");

		}



		MidOfStr(strtemp, num[2], strlen(num[2])-1, 1);

		if(strncmp(strtemp, "0", 1) == 0)			//当末尾有0时

		{

			strcpy(n[4], "");

		}

		

		MidOfStr(temp4, num[3], 0, 1);

		if(strncmp(temp4, "0", 1) == 0)				//分析千位

		{

			strcpy(n[5], numstr[1]);

		}

		else

		{

			strcpy(n[5], numstr[atoi(temp4)+1]);

			strcat(n[5], "仟");

		}



		MidOfStr(temp3, num[3], 1, 1);

		if(strncmp(temp3, "0", 1) == 0)				//分析百位

		{

			if(strncmp(temp4, "0", 1) == 0)

			{

				strcpy(n[6], "");

			}

			else

			{

				strcpy(n[6], numstr[1]);

			}

		}

		else

		{

			strcpy(n[6], numstr[atoi(temp3)+1]);

			strcat(n[6], "佰");

		}



		MidOfStr(temp2, num[3], 2, 1);

		if(strncmp(temp2, "0", 1) == 0)				//分析十位

		{

			if(strncmp(temp3, "0", 1) == 0)

			{

				strcpy(n[7], "");

			}

			else

			{

				strcpy(n[7], numstr[1]);

			}

		}

		else

		{

			strcpy(n[7], numstr[atoi(temp2)+1]);

			strcat(n[7], "拾");

		}



		MidOfStr(temp1, num[3], 3, 1);

		if(strncmp(temp1, "0", 1) == 0)				//分析个位

		{

			strcpy(n[8], "");

		}

		else

		{

			strcpy(n[8], numstr[atoi(temp1)+1]);

		}

		

		MidOfStr(strtemp, num[3], strlen(num[3])-3, 3);

		if(strncmp(strtemp, "000", 3) == 0)			//当末尾有000时

		{

			strcpy(n[6], "");

			strcpy(n[7], "");

			strcpy(n[8], "");

		}

		MidOfStr(strtemp, num[3], strlen(num[3])-2, 2);

		if(strncmp(strtemp, "00", 2) == 0)			//当末尾有00时

		{

			strcpy(n[7], "");

			strcpy(n[8], "");

		}

		MidOfStr(strtemp, num[3], strlen(num[3])-1, 1);

		if(strncmp(strtemp, "0", 1) == 0)			//当末尾有0时

		{

			strcpy(n[8], "");

		}



		//统计

		strcpy(number2, n[1]);

		strcat(number2, n[2]);

		strcat(number2, n[3]);

		strcat(number2, n[4]);

		strcat(number2, "万");



		if(strncmp(num[3], "0000", 4) == 0)

		{

			strcpy(number3, "");

			if(strncmp(num[2], "0000", 4) == 0)

			{

				strcpy(number2, "");

			}

		}

		else

		{

			if(strncmp(num[2], "0000", 4) == 0)

			{

				strcpy(number2, numstr[1]);

			}

			strcpy(number3, n[5]);

			strcat(number3, n[6]);

			strcat(number3, n[7]);

			strcat(number3, n[8]);

		}

		//取得整数位值

		strcpy(intstr, number1);

		strcat(intstr, number2);

		strcat(intstr, number3);

	}

	else if(intlen >= 5 && intlen <= 8)				//分析整数部分在10000~99999999之间的

	{

		MidOfStr(num[1], str1, 0, intlen-4);		//取得第一段(千万位到万位)



		//不足4位,用'0'补齐

		if(strlen(num[1]) == 3)

		{

			strcpy(strtemp, "0");

			strcat(strtemp, num[1]);

			strcpy(num[1], strtemp);

		}

		if(strlen(num[1]) == 2) 

		{

			strcpy(strtemp, "00");

			strcat(strtemp, num[1]);

			strcpy(num[1], strtemp);

		}

		if(strlen(num[1]) == 1)

		{

			strcpy(strtemp, "000");

			strcat(strtemp, num[1]);

			strcpy(num[1], strtemp);

		}



		MidOfStr(num[2], str1, intlen-4, 4);		//取得第二段(千位到个位)

		strcpy(number1,"");



		MidOfStr(temp8, num[1], 0, 1);

		if(strncmp(temp8, "0", 1) == 0)				//分析千万位

			strcpy(n[1], "");

		else

		{

			strcpy(n[1], numstr[atoi(temp8)+1]);

			strcat(n[1], "仟");

		}



		MidOfStr(temp7, num[1], 1, 1);

		if(strncmp(temp7, "0", 1) == 0)				//分析百万位

		{

			if(strncmp(temp8, "0", 1) == 0)

				strcpy(n[2], "");

			else

				strcpy(n[2], numstr[1]);

		}

		else

		{

			strcpy(n[2], numstr[atoi(temp7)+1]);

			strcat(n[2], "佰");

		}



		MidOfStr(temp6, num[1], 2, 1);

		if(strncmp(temp6, "0", 1) == 0)				//分析十万位

		{

			if(strncmp(temp7, "0", 1) == 0)

				strcpy(n[3], "");

			else

				strcpy(n[3], numstr[1]);

		}

		else

		{

			strcpy(n[3], numstr[atoi(temp6)+1]);

			strcat(n[3], "拾");

		}



		MidOfStr(temp5, num[1], 3, 1);

		if(strncmp(temp5, "0", 1) == 0)				//分析万位

			strcpy(n[4], "");

		else

			strcpy(n[4], numstr[atoi(temp5)+1]);

		

		MidOfStr(strtemp, num[1], strlen(num[1])-3, 3);

		if(strncmp(strtemp, "000", 3) == 0)			//当末尾有000时

		{

			strcpy(n[2], "");

			strcpy(n[3], "");

			strcpy(n[4], "");

		}

		MidOfStr(strtemp, num[1], strlen(num[1])-2, 2);

		if(strncmp(strtemp, "00", 2) == 0)			//当末尾有00时

		{

			strcpy(n[3], "");

			strcpy(n[4], "");

		}

		MidOfStr(strtemp, num[1], strlen(num[1])-1, 1);

		if(strncmp(strtemp, "0", 1) == 0)			//当末尾有0时

			strcpy(n[4], "");

		

		MidOfStr(temp4, num[2], 0, 1);

		if(strcmp(temp4, "0") == 0)					//分析千位

			strcpy(n[5], numstr[1]);

		else

		{

			strcpy(n[5], numstr[atoi(temp4)+1]);

			strcat(n[5], "仟");

		}



		MidOfStr(temp3, num[2], 1, 1);

		if(strncmp(temp3, "0", 1) == 0)				//分析百位

		{

			if (strncmp(temp4, "0", 1) == 0)

				strcpy(n[6], "");

			else

				strcpy(n[6], numstr[1]);

		}

		else

		{

			strcpy(n[6], numstr[atoi(temp3)+1]);

			strcat(n[6], "佰");

		}



		MidOfStr(temp2, num[2], 2, 1);

		if(strncmp(temp2, "0", 1) == 0)				//分析十位

		{

			if (strncmp(temp3, "0", 1) == 0)

				strcpy(n[7], "");

			else

				strcpy(n[7], numstr[1]);

		}

		else

		{

			strcpy(n[7], numstr[atoi(temp2)+1]);

			strcat(n[7], "拾");

		}



		MidOfStr(temp1, num[2], 3, 1);

		if(strncmp(temp1, "0", 1) == 0)				//分析个位

			strcpy(n[8], "");

		else

			strcpy(n[8], numstr[atoi(temp1)+1]);

		

		MidOfStr(strtemp, num[2], strlen(num[2])-3, 3);

		if(strncmp(strtemp, "000", 3) == 0)			//当末尾有000时

		{

			strcpy(n[6], "");

			strcpy(n[7], "");

			strcpy(n[8], "");

		}

		MidOfStr(strtemp, num[2], strlen(num[2])-2, 2);

		if(strncmp(strtemp, "00", 2) == 0)			//当末尾有00时

		{

			strcpy(n[7], "");

			strcpy(n[8], "");

		}

		MidOfStr(strtemp, num[2], strlen(num[2])-1, 1);

		if(strncmp(strtemp, "0", 1) == 0)			//当末尾有0时

			strcpy(n[8], "");



		//统计

		if(strncmp(num[2], "0000", 4) == 0)

			strcpy(number3, "");

		else

		{

			strcpy(number3, n[5]);

			strcat(number3, n[6]);

			strcat(number3, n[7]);

			strcat(number3, n[8]);

		}

		strcpy(number2, n[1]);

		strcat(number2, n[2]);

		strcat(number2, n[3]);

		strcat(number2, n[4]);

		strcat(number2, "万");

		//取得整数位值

		strcpy(intstr, number1);

		strcat(intstr, number2);

		strcat(intstr, number3);

	}

		

	else											//分析整数部分不到10000的

	{

		strcpy(num[1], str1);

		//不足4位,用'0'补齐

		if(strlen(num[1]) == 3)

		{

			strcpy(strtemp, "0");

			strcat(strtemp, num[1]);

			strcpy(num[1], strtemp);

		}

		if(strlen(num[1]) == 2)

		{

			strcpy(strtemp, "00");

			strcat(strtemp, num[1]);

			strcpy(num[1], strtemp);

		}

		if(strlen(num[1]) == 1)

		{

			strcpy(strtemp, "000");

			strcat(strtemp, num[1]);

			strcpy(num[1], strtemp);

		}

		strcpy(number1, "");

		strcpy(number2, "");



		MidOfStr(temp4, num[1], 0, 1);

		if(strncmp(temp4, "0", 1) == 0)				//分析千位

			strcpy(n[1], "");

		else

		{

			strcpy(n[1], numstr[atoi(temp4)+1]);

			strcat(n[1], "仟");

		}



		MidOfStr(temp3, num[1], 1, 1);

		if(strncmp(temp3, "0", 1) == 0)				//分析百位

		{

			if(strncmp(temp4, "0", 1) == 0)

				strcpy(n[2], "");

			else

				strcpy(n[2], numstr[1]);

		}

		else

		{

			strcpy(n[2], numstr[atoi(temp3)+1]);

			strcat(n[2], "佰");

		}



		MidOfStr(temp2, num[1], 2, 1);

		if(strncmp(temp2, "0", 1) == 0)				//分析十位

		{

			if (strncmp(temp3, "0", 1) == 0)

				strcpy(n[3], "");

			else

				strcpy(n[3], numstr[1]);

		}

		else

		{

			strcpy(n[3], numstr[atoi(temp2)+1]);

			strcat(n[3], "拾");

		}



		MidOfStr(temp1, num[1], 3, 1);

		if(strncmp(temp1, "0", 1) == 0)				//分析个位

			strcpy(n[4], "");

		else

			strcpy(n[4], numstr[atoi(temp1)+1]);

		

		MidOfStr(strtemp, num[1], strlen(num[1])-3, 3);

		if(strncmp(strtemp, "000", 3) == 0)			//当末尾有000时

		{

			strcpy(n[2], "");

			strcpy(n[3], "");

			strcpy(n[4], "");

		}

		MidOfStr(strtemp, num[1], strlen(num[1])-2, 2);

		if(strncmp(strtemp, "00", 2) == 0)			//当末尾有00时

		{

			strcpy(n[3], "");

			strcpy(n[4], "");

		}

		MidOfStr(strtemp, num[1], strlen(num[1])-1, 1);

		if(strncmp(strtemp, "0", 1) == 0)			//当末尾有0时

			strcpy(n[4], "");

		

		//统计

		strcpy(number3, n[1]);

		strcat(number3, n[2]);

		strcat(number3, n[3]);

		strcat(number3, n[4]);

		////取得整数位值

		strcpy(intstr, number1);

		strcat(intstr, number2);

		strcat(intstr, number3);

	}

	if(strcmp(str1, "0") == 0)						//如果整数为零,转换为"零"

		strcpy(intstr, numstr[1]);

		

//*****分析和转换小数部分*****



	if(cntype == 0)									//如果转换为人民币表达式

	{

		MidOfStr(strtemp, str2, 0, 1);		

		if(strncmp(strtemp, "0", 1) == 0)

			strcpy(n[1], "零");

		else

		{

			strcpy(n[1], numstr[atoi(strtemp)+1]);

			strcat(n[1], "角");

		}

		MidOfStr(temp0, str2, 1, 1);

		if(strncmp(temp0, "0", 1) == 0)

			strcpy(n[2], "");

		else

		{

			strcpy(n[2], numstr[atoi(temp0)+1]);

			strcat(n[2], "分");

		}

		strcpy(decstr, n[1]);

		strcat(decstr, n[2]);

	}

	if (cntype == 1)								//如果转换为数字表达式

	{

		unsigned int decpos;

		strcpy(decstr, "");

		for(decpos = 0; decpos < strlen(str2); decpos ++)

		{

			MidOfStr(temp0, str2, decpos, 1);

			strcpy(n[decpos], numstr[atoi(temp0)+1]);

			strcat(decstr, n[decpos]);

		}

	}



//输出本函数的结果***********************



	if(cntype == 0)									//将数字字串转换为人民币的大写格式

	{

		if(strcmp(str2, "") == 0)					//如果为纯整数

		{

			strcpy(strtemp, intstr);

			strcat(strtemp, "元整");

			strcpy(outstr, strtemp);

		}

		else

		{

			if(strcmp(intstr, "零") == 0)			//如果整数为零,就只显示小数

				strcpy(outstr, decstr);

			else

			{

				strcpy(strtemp, intstr);

				strcat(strtemp, "元");

				strcat(strtemp, decstr);

				strcpy(outstr, strtemp);

			}

		}

	}

	if(cntype == 1)									//将数字字串转换为普通大写格式

	{

		if(strcmp(str2, "") == 0)					//如果为纯整数

			strcpy(outstr, intstr);

		else

		{

			strcpy(strtemp, intstr);

			strcat(strtemp, "点");

			strcat(strtemp, decstr);

			strcpy(outstr, strtemp);

		}

	}

    

	if(qxf_flag==1)

	{

		char qxf_temp[200];

		strcpy(qxf_temp,"负");

		strcat(qxf_temp,outstr);

		strcpy(outstr,qxf_temp);

	}

	

	//完毕OK

}





void reverse(char * pStr)

{

	char *pTemp;

	int i,Len;

	Len = strlen(pStr);

	pTemp = new char[Len+1];

	strcpy(pTemp,pStr);

	for (i = Len - 1;i >= 0;i--)

		*(pStr + Len - i - 1) = *(pTemp + i);

	delete pTemp;

}





void YhCrypt(char *pDst,char *pSrc)

{

	int i;

	char *pTemp,*pTempTemp;

	pTempTemp = NULL;

	pTemp = NULL;

	if (strlen(pSrc) == 0)

		strcpy(pDst,"119");

	else

	{

		pTemp = new char[strlen(pSrc) + 1];

		pTempTemp = new char[strlen(pSrc) + 1];

		strcpy(pTemp,pSrc);

		i = 0;

		for (;;)

		{

			reverse(pTemp);

			pDst[i++] = *pTemp + 32 - strlen(pTemp)* 2;

			strcpy(pTempTemp,pTemp+1);

			strcpy(pTemp,pTempTemp);

			if (strlen(pTemp) == 0) break;

		}

		pDst[i] = '\0';

	}

	delete pTemp;

	delete pTempTemp;

}



⌨️ 快捷键说明

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