c语言 找数字有一样的数
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 19:48:12
c语言 找数字有一样的数
Problem:Two integers are considered to be friendly if all of the digits in the first number appear in the second number.Given ten integers as input display all pairs of “friends” in the set where the second number must come after (order of input) the first in the data set.
• The user will always enter 10 non-negative integers as input.Leading zero digits are ignored.
• Display no more than 5 pairs of friends per line of output.
Example Execution #1:
Enter data #1:1234
Enter data #2:4321
Enter data #3:2111
Enter data #4:12345
Enter data #5:5432
Enter data #6:23451
Enter data #7:3
Enter data #8:2341112
Enter data #9:5423
Enter data #10:3
Friends:[1234,4321] [1234,12345] [1234,23451] [1234,2341112] [4321,12345]
[4321,23451] [4321,2341112] [2111,12345] [2111,23451] [2111,2341112]
[12345,23451] [5432,23451] [5432,5423] [3,2341112] [3,5423]
[3,3]
大概就是.只要第一个数里的数字在另外一个数里全部出现.就输出.
最好输出格式和例题一样.
现在完全没有头绪.马上要交了.
Problem:Two integers are considered to be friendly if all of the digits in the first number appear in the second number.Given ten integers as input display all pairs of “friends” in the set where the second number must come after (order of input) the first in the data set.
• The user will always enter 10 non-negative integers as input.Leading zero digits are ignored.
• Display no more than 5 pairs of friends per line of output.
Example Execution #1:
Enter data #1:1234
Enter data #2:4321
Enter data #3:2111
Enter data #4:12345
Enter data #5:5432
Enter data #6:23451
Enter data #7:3
Enter data #8:2341112
Enter data #9:5423
Enter data #10:3
Friends:[1234,4321] [1234,12345] [1234,23451] [1234,2341112] [4321,12345]
[4321,23451] [4321,2341112] [2111,12345] [2111,23451] [2111,2341112]
[12345,23451] [5432,23451] [5432,5423] [3,2341112] [3,5423]
[3,3]
大概就是.只要第一个数里的数字在另外一个数里全部出现.就输出.
最好输出格式和例题一样.
现在完全没有头绪.马上要交了.
#include
#include
#include
#define N 10
#define MAX_LEN 100
int friend(char * a, char * b)
{
int i;
while (*a)
{
for (i = 0; b[i] != '\0'; i++)
if (b[i] == *a)
break;
if (b[i] == '\0')
return 0;
a++;
}
return 1;
}
int main()
{
char data[N][MAX_LEN];
char s[MAX_LEN], * p;
int i, j, align = 0, n = 0;
puts("Example Execution #1:");
for (i = 0; i < N; i++)
{
printf("Enter data #%d: ", i);
scanf("%s", s);
p = s;
while (*p == '0' && p[1] != '\0') p++;
strcpy(data[n++], p);
}
printf("Friends: ");
for (i = 0; i < N; i++)
{
for (j = i + 1; j < N; j++)
if (friend(data[i], data[j]))
{
if (align % 5 != 0)
putchar(' ');
printf("[%s, %s]", data[i], data[j]);
if (align % 5 == 4)
putchar('\n');
align++;
}
}
return 0;
}
#include
#include
#define N 10
#define MAX_LEN 100
int friend(char * a, char * b)
{
int i;
while (*a)
{
for (i = 0; b[i] != '\0'; i++)
if (b[i] == *a)
break;
if (b[i] == '\0')
return 0;
a++;
}
return 1;
}
int main()
{
char data[N][MAX_LEN];
char s[MAX_LEN], * p;
int i, j, align = 0, n = 0;
puts("Example Execution #1:");
for (i = 0; i < N; i++)
{
printf("Enter data #%d: ", i);
scanf("%s", s);
p = s;
while (*p == '0' && p[1] != '\0') p++;
strcpy(data[n++], p);
}
printf("Friends: ");
for (i = 0; i < N; i++)
{
for (j = i + 1; j < N; j++)
if (friend(data[i], data[j]))
{
if (align % 5 != 0)
putchar(' ');
printf("[%s, %s]", data[i], data[j]);
if (align % 5 == 4)
putchar('\n');
align++;
}
}
return 0;
}
c语言 找数字有一样的数
C语言,找满足要求的数字.
用C语言实现 输出0-99999中可开方数并且其中有两个数字是一样的如144,121等
找满足要求的数字(C语言)
找满足要求的数字(C语言),
c语言一个数分解成独立的数字
C语言编程:求100~999中个位数、十位数、百位数字之和为21的数有哪些
C语言编程实现用9个数字排成没有重复数字的完全平方数
10个数找最大值并标出是第几个数字的C语言
c语言 填空判断回文数 就是从左到右和从右到左读是一样的数谢谢
C语言循环语句题有1、2、3、4四个数字,能组成多少个互不相同且无重复数字的三位数,都是哪些数?
从键盘输入一个三位整数,分别输出该数的个位数字,十位数字,百位数字,c语言,求急啊