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

#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
int main()
{

/*
* 给定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
*/

int arrary[10] = { 0 };
int count = 0;
cin >> count;
int sum=0;
if (count > 9)
{
return 0;
}
for (size_t i = 0; i < count; i++)
{
cin >> arrary[i];
}
for (size_t i = 0; i < count; i++)
{
int x = arrary[i];
for (size_t j = 0; j < count; j++)
{
if (arrary[j] != x)
{
int y = arrary[j];
sum += x*10+y;
}
}
}
cout << sum;
return 0;
}

posted @ 2018-04-15 13:33  jieche  阅读(8310)  评论(0编辑  收藏  举报