关于 cin cout 加速
查看原帖
关于 cin cout 加速
1093380
zhangfengkai001楼主2024/12/31 23:11
#include<iostream>
using namespace std;

const char F = 'F',
		   B = 'B',
		   R = 'R';

int logo()
{
	ios::sync_with_stdio(0), cin.tie(0);
	char op, x;
	string w;
	int v, ans = 0;
	while (cin >> op)
	{
		if (op == ']') break;
		cin >> w
			>> v;
		//cout<<"op"<<' '<<op<<' '<<w<<' '<<v<<'\n';
		if (op == F)
		{
			ans += v;
			x = getchar();
		}
		if (op == B)
		{
			ans -= v;
			x = getchar();
		}
		if (op == R)
		{
			x = getchar();
			//cout<<"x"<<' '<<x<<' ';
			ans += v * logo();
			x = getchar();
			//cout<<x<<' '<<"x"<<'\n';
		}
		if (x == ']') break;
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(0), cout.tie(0);
	cout << abs(logo());
	return 0;
}

A不了,但删去ios::sync_with_stdio(0), cout.tie(0);ios::sync_with_stdio(0), cin.tie(0);就行。

Why?

2024/12/31 23:11
加载中...