1066: 竖式问题

#include <bits/stdc++.h>
using namespace std;
char c[20];
int a[20];
int b[20]; 
bool judge(int num){
	if(num==0){
		return b[0];
	}
	while(num){
		if(b[num%10]){
			num/=10;
		}
		else 
			return 0;
	}
	return 1;
}
int main(){
	while(scanf("%s",c+1)!=EOF){
		int len=strlen(c+1);
		memset(b,0,sizeof(b));
		int j=-1;
		for(int i=1;i<=len;i++){
			b[c[i]-'0']=1;
		}
		int ans=0;
		for(int i=100;i<=999;i++){
			for(int j=10;j<=99;j++){
				int temp1=i*(j%10);
				int temp2=i*(j/10);
				int temp3=i*j;
				if(judge(i)&&judge(j)&&judge(temp1)&&judge(temp2)&&judge(temp3)){
					ans++;
					printf("<%d>\n",ans);
					printf("%5d\n",i);
					printf("X%4d\n",j);
					printf("-----\n");
					printf("%5d\n",temp1);
					printf("%4d\n",temp2);
					printf("-----\n");
					printf("%5d\n",temp3);
					printf("\n");
				}
			}
		}
								
	printf("The number of solutions: %d\n",ans);
	}
	return 0;
}
posted @ 2026-02-27 00:05  peter_shen  阅读(6)  评论(0)    收藏  举报