Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- int num,r,a[500];
- cin>>num;
- for (int i=0;i<num;i++)
- {
- cin>>r;
- int last,z=0;
- for (int j=0;j<r;j++)
- {
- cin>>a[j];
- }
- for (int j=0;j<r;j++)
- {
- int first=0;
- for (int k=0;k<r;k++)
- {
- first+=abs(a[j]-a[k]);
- }
- if (z==0) // 第一次強制紀錄
- {
- last=first;
- z++;
- }
- if (first<last) // 若前一次比較小就紀錄
- {
- last=first;
- }
- }
- cout<<last<<endl;
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment