#include #include #include using namespace std;

int a[100010]; // 定义一个数组a,大小为100010

int f(int n){ // 定义一个函数f,参数为n,返回值为一个整数 int m; // 定义一个整数m m=n%2; // 将n对2取余赋值给m if(!m) return 0; // 如果m为0,返回0 return 1; // 否则返回1 }

int main() { int n,i,p,q,s1=0,s2=0,m; // 定义整数n,i,p,q,s1,s2,m,并将s1和s2初始化为0 cin>>n; // 从标准输入读取一个整数赋值给n for(i=0;i<n;i++) // 循环n次,从标准输入读取n个整数赋值给数组a cin>>a[i]; sort(a,a+n); // 对数组a进行排序 if(f(n)){ // 调用函数f,如果返回值为true p=n/2+1; // 将n除以2再加1赋值给p q=n/2; // 将n除以2赋值给q } else{ // 否则 p=n/2; // 将n除以2赋值给p q=n/2; // 将n除以2赋值给q
} for(i=0;i<q;i++) // 循环q次,将数组a的前q个元素相加赋值给s1 s1+=a[i]; for(i=q;i<n;i++) // 循环从q到n-1,将数组a的后n-q个元素相加赋值给s2 s2+=a[i]; m=abs(s1-s2); // 将s1和s2的差的绝对值赋值给m cout<<"Outgoing #: "<<p<<endl; // 输出Outgoing #: 和p的值 cout<<"Introverted #: "<<q<<endl; // 输出Introverted #: 和q的值 cout<<"Diff = "<<m<<endl; // 输出Diff = 和m的值 return 0;

在该程序中给出注释#include iostream#include vector#include algorithmusing namespace std;int a100010;int fint n int m; m=n2; if!m return 0; return 1; int main int nipqs1=0s2=0m; cinn; fori=

原文地址: https://www.cveoy.top/t/topic/iCzz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录