算法竞赛入门(第二版)--java实现.3.2字符数组.竖式问题

package unit3;
import java.util.Scanner;

public class ShuShiQuestion {
    public static void main(String args[]) {
    	Scanner input = new Scanner(System.in);
    	int number = input.nextInt();
    	String check = ""+number;
    	int counts = 0;
    	for(int i = 111;i <= 999;i++) {
    		for(int n = 11;n <= 99;n++) {
    			int numbers = i*n;
    			String token = ""+i+n+i*(n%10)+i*(n/10)+numbers;   //将两个乘数、竖式两个过程、结果保留到一个字符串中
    			int count = 0;        //记录存在输入字符中的字符的个数
    			for(int k = 0;k < token.length();k++) {  //检查每一个字符是否都在输入字符串中,类似于实例程序中的strchr(s,buf[i])函数
    				int key = 0;
    				for(int m = 0;m < check.length();m++) {
    					if(token.charAt(k) == check.charAt(m)) {
    						key = 1;
    					}
    				}
    				if(key == 1) {
    					count++;
    				}
    			}
    			if(count == token.length()) {       //每一个字符都属于输入字符串,输出
    				counts++;
        			System.out.printf("%5d\n*%4d\n-----\n%5d\n%4d\n-----\n%5d\n\n",i,n,i*(n%10),i*(n/10),i*n);      
    			}
    		}
    		
    	}
    	System.out.print("The number of solutions: "+counts);        
    }
    
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值