版权声明:Copright ©2017 By CangyeChen https://blog.csdn.net/CANGYE0504/article/details/72802302
1056. 组合数的和(15)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
给定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
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int sum=0,N;
cin >> N;
int a[N];
for(int i=0;i<N;i++)
{
cin>>a[i];
}
for(int s=0;s<N;s++)
{
for(int t=s+1;t<N;t++)
{
sum = sum+a[s]*10+a[t]+a[t]*10+a[s];
}
}
cout << sum;
return 0;
}