示例#1
0
文件: PALIN.c 项目: TheKingSlayer/TPC
void increment_string(char* pString, int lastNdx)
{
	if(lastNdx==0)
	{
		if(pString[0]=='9')
		{
			pString[0] = '0';
			ALLNINE = 1;
			return;
		}
		// increment the char
		pString[0]++;
		return;
	}
	else
	{
		if(pString[lastNdx]=='9')
		{

			pString[lastNdx]='0';
			increment_string(pString,--lastNdx);
		}
		else
		{
			pString[lastNdx]++;
		}
	}
}
示例#2
0
void StringData::inc() {
  ASSERT(!isStatic());
  ASSERT(!empty());
  if (isImmutable()) {
    escalate();
  }
  StringSlice s = slice();
  // if increment_string overflows, it returns a new ptr and updates s.len
  ASSERT(int(s.len) >= 0 && s.len <= MaxSize); // safe int/uint casting
  int len = s.len;
  char *overflowed = increment_string((char *)s.ptr, len);
  if (overflowed) attach(overflowed, len);
  m_hash = 0;
}
示例#3
0
void StringData::inc() {
  if (empty()) {
    m_len = (IsLiteral | 1);
    m_data = "1";
    return;
  }
  if (isImmutable()) {
    escalate();
  }
  char *overflowed = increment_string((char *)m_data, size());
  if (overflowed) {
    assign(overflowed, AttachString);
  }
}
示例#4
0
文件: PALIN.c 项目: TheKingSlayer/TPC
void palin	(char* pStr)
{
		int	len, midndx, left, right, status;

	len		= strlen(pStr);
	STRLEN	= len;
	// Even
	if(len%2==0)
	{
		right	= len/2;
		left	= right-1;
		status	= type(pStr,left,right);

		// left>right
		if(status==1)
		{
			pStr[right]='\0';
			print_even(pStr);
		}
		else
		{
			increment_string(pStr,left);
			if(ALLNINE)
			{
				memset(pStr,'0',sizeof(char)*STRLEN);

				pStr[STRLEN+1]='\0';
				pStr[0]='1';
				pStr[STRLEN]='1';
				printf("%s\n",pStr);
			}
			else
			{
				pStr[right]	= '\0';
				print_even(pStr);
			}
		}
	}
	else
	// Odd
	{
		midndx	= len/2;
		left	= midndx-1;
		right	= midndx+1;
		status	= type(pStr,left,right);

		if(status==1)
		{
			pStr[right]='\0';
			print_odd(pStr);
		}
		else
		{
			increment_string(pStr,midndx);
			if(ALLNINE)
			{
				memset(pStr,'0',sizeof(char)*STRLEN);
				pStr[STRLEN+1]='\0';
				pStr[0]='1';
				pStr[STRLEN]='1';
				printf("%s\n",pStr);
			}
			else
			{
				pStr[right]='\0';
				print_odd(pStr);
			}
		}
	}
}