Java 洛谷 P1149 火柴棒等式
生活随笔
收集整理的這篇文章主要介紹了
Java 洛谷 P1149 火柴棒等式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:https://www.luogu.com.cn/problem/P1149
代碼實例:
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int input = scanner.nextInt();int count = 0;int c[] = new int[2001];c[0] = 6;//a存儲0-9每個數字所用的火柴數目int a[] = new int [] {6,2,5,5,4,5,6,3,7,6};for(int i=1;i<=2000;i++) {int j=i;while(j>=1)//求每個數所用的火柴棒{c[i] += a[j%10];j=j/10;}}for (int i = 0; i < 1000; i++) {for (int j = 0; j < 1000; j++) {if(c[i]+c[j]+c[i+j]+4==input) {count++;}}}System.out.println(count);scanner.close();} }總結
以上是生活随笔為你收集整理的Java 洛谷 P1149 火柴棒等式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java洛谷P1149 火柴棒等式
- 下一篇: Java 洛谷 P2089 烤鸡