描述
竖式问题:找出一个三位*二位的版式,使得在完整的竖式中,所有数字都属于一个特定的数字集合S.
每组测试输出测试号,每组测试内有多组符合要求的数据,输出序列号及竖式,及本测试内符号要求人竖式量。如果没有找到满足条件的竖式,则the number of solutions=0;
输入
数字集合S.
输出
每组测试输出测试号,每组测试内有多组符合要求的数据,输出序列号及竖式,及本测试内符号要求人竖式量。如果没有找到满足条件的竖式,则the number of solutions=0;
样例输入:2357 //2 3 5 7 四个字符
样例输出:
CASE #1
<1>
775
X 33
-----
2325
2325.
-----
25575
the number of solutions=1
样例输入
2357
样例输出
CASE #1
<1>
775
X 33
-----
2325
2325
-----
25575
the number of solutions=1
思路
输入格式要注意
code
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<set>
#include<string>
using namespace std;
int main()
{
string input;
int round1=0;
while(cin>>input){
printf("CASE #%d\n",++round1);
int count1=0;
for(int num1=100;num1<=999;num1++){
for(int num2=10;num2<=99;num2++){
int a = num1*(num2%10);
int b = num1*(num2/10);
int c = num1*num2;
string ss = to_string(num1)+to_string(num2)+to_string(a)+\
to_string(b)+to_string(c);
bool flag=true;
for(int i=0;i<ss.size();i++){
if(input.find(ss[i])==-1){
flag=false;
}
}
if(flag){
printf("<%d>\n",++count1);
printf("%5d\n",num1);
printf("X%4d\n",num2);
printf("-----\n");
printf("%5d\n",a);
printf("%4d\n",b);
printf("-----\n");
printf("%5d\n",c);
}
}
}
printf("the number of solutions=%d\n", count1);
}
return 0
}