算法问题
Problem Description
Give you n elements a1, a2, a3,..., an.You need to calculate the sum of (a1 * a1 * a1 + a2 * a2 * a2 + ... + an * an * an).
Input
The first line of the input contains an integer T(1<=T<=10) which means the number of test cases.
Each case starts with a line containing a integers n(1 <= n <= 1,000).
The next line contains n space-separated elements ai (1 <= i <= n), and 0 <= ai <= 100,000.
Output
For each case, you need to print the answer in a single line.
Sample Input
2
2
1 1
3
2 4 7
Sample Output
2
415
这是一道ACM的训练题
以下是我的的代码
#include <iostream>
using namespace std;
int main()
{
int T;
cin >> T;
int T1 = T;
int a[1005],t;
int i,j = 0;
long long s[15] = { 0 };
while (T--)
{
cin >> t;
for (i = 0; i < t; i++)
{
cin >> a[i];
s[j] += a[i] * a[i] * a[i];
}
j++;
}
i = 0;
while (T1--)
{
cout << s[i] << endl;
i++;
}
return 0;
}
我调试的时候没有发现错误,内存方面longlong是支撑的起的,但是答案就是错的,不清楚为什么。