题目:
1. 求一个整型数字中有没有相同的部分,例如12389756123这个整型数字中相同的部分是123,相同的部分至少应该是2位数,如果有相同部分返回1,如果没有则返回0。方法是先将整型数字转换到数组中,再判断。
代码:
#include<stdio.h>
#include<stdlib.h>
int verified(int a)
{
char b[100];
int c = 0,b_i = 0;
// while(a) //该方法int a在数组中是倒序的
// {
// c = a%10;
// a /= 10;
// b[b_i] = c;
// b_i++;
// }
//char * p = (char *)malloc(sizeof(char));
char temp[100];
char * p = temp;
itoa(a,temp,10);
while(*p)
{
// printf("%c",*p);
b[b_i] = * p;
b_i++;
p++;
}
for(int i = 0;i < b_i;i++)
{
for(int j = i + 2;j < b_i;j++)
{
if((b[i] == b[j]) && (b[i + 1] == b[j + 1]))
{
return 1;
}
}
}
return 0;
}
void main()
{
int a = 123213;
int b = verified(a);
printf("%d",b);
}