PAT——1056. 组合数的和

给定N个非0的个位数字,用其中任意2个数字都可以组合成1个2位的数字。要求所有可能组合出来的2位数字的和。例如给定2、5、8,则可以组合出:25、28、52、58、82、85,它们的和为330。

输入格式:

输入在一行中先给出N(1<N<10),随后是N个不同的非0个位数字。数字间以空格分隔。

输出格式:

输出所有可能组合出来的2位数字的和。

输入样例:

3 2 8 5

输出样例:

330


 1 package com.hone.basical;
 2 import java.util.Scanner;
 3 /**
 4  * 原题目:https://www.patest.cn/contests/pat-b-practise/1056
 5  * @author Xia
 6  * 利用两个for循环,任意组合即可。
 7  */
 8 
 9 public class basicalLevel1056combinateNum {
10     public static void main(String[] args) {
11         Scanner in = new Scanner(System.in);
12         int N = in.nextInt();        //总个数
13         int[] a = new int[N];
14         for (int i = 0; i < N; i++) {
15             a[i] = in.nextInt();
16         }
17         int sum = 0;
18         for (int i = 0; i < N; i++) {
19             for (int j = 0; j < N; j++) {
20                 if (i!=j) {
21                     sum+=(a[i]*10+a[j]);
22                 }
23             }
24         }
25         System.out.println(sum);
26     }
27 }
原文地址:https://www.cnblogs.com/xiaxj/p/8004335.html