字符串处理函数strchr() && 竖式问题

竖式问题
| 题目描述 | 
| 找出所有形如abc*de(三位数乘两位数)的算式,使得在完整的竖式中,所有数字都属于一个特定的数字集合。 | 
| 输入: | 
| 输入一个数字集合(相邻数字之间没有空格) | 
| 输出: | 
| 输出所有竖式.每个竖式前应该编号,之后应该有一个空行。最后输出解的总数。 | 
| 样例输入: | 
| 2357 | 
| 样例输出: | 
(1)   775 x  33 -----  2325 2325  ----- 25575
  The number of solution = 1 | 
分析
小学的乘法运算

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
   | #include<stdio.h> #include<string.h> int main() {     int count; 	char s[20],buf[99]; 	scanf("%s",s); 	for(int abc = 111;abc <= 999;abc++) 	{ 		for(int de = 11;de <= 99;de++) 		{ 			int x = abc*(de%10),y = abc*(de/10),z = abc*de; 			sprintf(buf,"%d%d%d%d%d",abc,de,x,y,z); 			
 
 
  			int ok = 1; 			for(int i = 0;i<strlen(buf);i++) 			{ 				if(strchr(s,buf[i])==NULL) ok = 0; 			} 			if(ok) 			{ 				printf("(%d)\n",++count); 				printf("%5d\nx%4d\n-----\n%5d\n%4d\n-----\n%5d\n\n",abc,de,x,y,z); 			} 		} 	} 	printf("The number of solutions = %d\n",count); 	return 0; }
   | 
 

字符处理函数strchr()
strchr() 用来查找某字符在字符串中首次出现的位置,其原型为:
char * strchr (const char *str, int c);
- strchr() 将会找出 str 字符串中第一次出现的字符 c 的地址,然后将该地址返回。
 
- 如果找到指定的字符则返回该字符所在地址,否则返回 NULL。
 
1 2 3 4 5 6 7 8 9 10
   | #include<stdio.h> #include<string.h> int main() { 	char *s="666shansan"; 	char *p; 	p = strchr(s,'s'); 	printf("%s",p); 	return 0; }
   | 
 
输出结果
shansan