scanf输入会导致WA?不知道哪里出的问题
查看原帖
scanf输入会导致WA?不知道哪里出的问题
31585
2002chenhan楼主2022/5/11 20:47

错误已定位于主函数
用scanf输入会WA,二用cin处理才能AC。这是为什么?

这样子是WA

char opt[10];
int main()
{
	int n;scanf("%d",&n);
	const int root=1;
	build(root, 1, 50000);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",opt);
		if(opt[0]=='P')
		{
			Line now;
			scanf("%lf%lf",&now.b,&now.k);
			now.b=now.b-now.k;
			now.l=1;now.r=50000;
			modify(root, 1, 50000, now);
		}
		else
		{
			int day;scanf("%d",&day);
			double ans=query(root, 1, 50000, day);
			printf("%d\n",floor(ans/100));
		}
	}
	return 0;
}

这样能AC

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;cin>>n;
	const int root=1;
	build(root, 1, 50000);
	for(int i=1;i<=n;i++)
	{
        string opt;
        cin >> opt;
		if (opt[0] == 'P') {
            double s, p;
            cin >> s >> p;
            Line now; now.l = 1; now.r = 50000; now.k = p; now.b = s - p;
            modify(1, 1, 50000, now);
        }
        else {
            int x;
            cin >> x;
            cout << floor(query(1, 1, 50000, x) / 100) << "\n";
        }
	}
	return 0;
}

有人能帮我看看嘛?

2022/5/11 20:47
加载中...