c++程序问题

NeilKleist 2016-10-20 07:18:13
如题,以下有一段程序(我同学写的orz),貌似出现了一点问题,希望各位大神帮忙解决
#include<cstdio>
#include<algorithm>
using namespace std;
struct s{
long shu;
long hao;
}a[100050],b[100050];
void jh(long *a,long *b)
{
*a+=*b;
*b=*a-*b;
*a-=*b;
}
int px(const s & a,const s & b)
{
return (a.shu<b.shu);
}
int ph(const s & a,const s & b)
{
return (a.hao<b.hao);
}
int main()
{
long n;
long num=0;
long i;
scanf("%ld",&n);
for(i=0;i<n;i++)
{
scanf("%ld",&a[i].shu);
a[i].hao=i;
//printf("@%d\n",i);
}
//printf("a完\n");

i=0;
for(i=0;i<n;i++);
{
//printf("%d#@%\n",i);
scanf("%ld",&b[i].shu);
b[i].hao=i;
//printf("@%d\n",i);
}
//printf("b完\n");
sort(a,a+n-1,px);
sort(b,b+n-1,px);
for(i=0;i<n;i++)
a[i].shu=b[i].hao;
sort(a,a+n-1,ph);
for(i=0;i<n;i++)
{
//printf("%d %d\n",a[i].hao,a[i].shu);
if(a[i].hao<a[i].shu)
{
num+=a[i].hao-a[i].shu;
}
}
printf("%ld",num%99999997);
return 0;
}

(原题目:https://www.luogu.org/problem/show?pid=1966
...全文
582 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

3,882

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧