例如输入:abcd123.4567.890.123
输出:123.4567.890
“.”可以作为连接符连接两个数字,但是要求"."两边必须都是数字。
面试时遇到的题,因为忽略了对‘0’的处理,所以挂了。
#include
#include
#define MAX_SIZE 0x500
bool IsDotCorrect(char*szInput, int i, int nLastCmpPos, int nLen)//Check if it's a correct dot.
{
if (nLastCmpPos < 0)
{
return false;
}
if ((i - 1 >= 0 && i + 1 = '0' && szInput[i - 1] = '0' && szInput[i + 1] = '0' && szInput[i] = 0)//if it's first correct char, no need to compare
{
if (nCount == 0) //first num in this loop ,no need to compare
{
nCount++;
}
else
{
if (((szInput[i] - szInput[nLastCmpPos]) == 1) && szInput[nLastCmpPos] != '0')
{
nCount++;
}
else if (szInput[i] == '0' && szInput[nLastCmpPos] == '9')
{
nCount++;
}
else
{
bIsCount = false;
}
/*if (szInput[i] == '0' && szInput[nLastCmpPos] == '9')
{
nCount++;
}*/
}
}
else//first num ++
{
nCount++;
}
nLastCmpPos = i;
}
if (!bIsCount)//Count start
{
bIsCount = false;//Count again
if (nCountBak
关注
打赏
热门博文
- ArrayList c.toArray might (incorrectly) not return Object[] (see 6260652)
- Spring框架实体bean转json返回前端报错:Null key for a Map not allowed in JSON (use a converting NullKeySerializer
- python将数据写入txt文本文件
- Python学习随笔:使用xlwings读取和操作Execl文件
- org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized t
- ‘gbk‘ codec can‘t decode byte 0x80 in position 2: illegal multibyte sequence
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- 关于Mybatis中keyProperty属性
- 解决 Mybatis 报错 org.apache.ibatis.ognl.NoSuchPropertyException: XXXCriteria$Criterion.noValue
- mysql报错 is longer than the server configured value of ‘wait_timeout‘
