思路:這是很簡單的一道題,我們只需要用兩個for循環將兩個數字組合,由於不存在任何兩個相同的數字我們還要求出他們十位和個位對調之後的數字,再加起來就可以了。
#include<cstdio>
using namespace std;
int main(){
int N,n[12];
scanf("%d",&N);
for(int i=0;i<N;i++)
scanf("%d",&n[i]);
int temp1=0,temp2=0,sum=0;
for(int i=0;i<N;i++){
for(int j=i+1;j<N;j++){
temp1=n[i]*10+n[j];
temp2=n[j]*10+n[i];
sum=sum+temp1+temp2;
}
}
printf("%d",sum);
return 0;
}
題目鏈接: