6/9~6/11总结

第二周任务 [Cloned] - Virtual Judge (vjudge.net)

H - Writing a Numeral

根据不同的指令去执行对应的操作即可

如果是1就将输入的值推入队列,并且即使计算ans

q.push(c);

ans = (ans * 10 + c) % mod;

如果是2就将队首出队,ans要减去队首元素乘以队列长度,

x = q.front(); q.pop(); ans = (ll)(ans - x * a[q.size()] % mod + mod) % mod;

注意将负数控制在mod范围内

void init() { //预处理 a[0] = 1; for (int i = 1; i < maxn; i++) { a[i] = a[i - 1] * 10 % mod; } }

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ms(x,y) memset(x,y,sizeof x);
#define endl cout<<'\n';
#define int long long
typedef long long ll;
const int maxn = 6e5 + 10, inf = 1e18;
using namespace std;
int a[maxn];
int mod = 998244353;
string s = "1";
int ans = 1;
queueq;
void solve() {
	int n;
	cin >> n;
	if (n == 3) {
		cout << ans % mod << '\n';
	}
	if (n == 1) {
		int c;
		cin >> c;
		q.push(c);
		ans = (ans * 10 + c) % mod;
	}
	if (n == 2) {
		int x;
		x = q.front();
		q.pop();
		ans = (ll)(ans - x * a[q.size()] % mod + mod) % mod;
	}
}
void init() {  //预处理//这样为什么能防止负数
	a[0] = 1;
	for (int i = 1; i < maxn; i++) {
		a[i] = a[i - 1] * 10 % mod;
	}
}
signed main()
{
	//ios::sync_with_stdio(false);
	init();
	q.push(1);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
}

第二周任务 [Cloned] - Virtual Judge (vjudge.net)

E - Dango

如果没有o或-就输出-1

否则就计数连续的o即可


#include
using namespace std;
char A[200005];
int main()
{
	int n;
	cin >> n;
	cin >> A;
	int sum = 0;
	int max = -10;
	int cnt1 = 0;
	int cnt2 = 0;
	for (int i = 0,j=0; i < n; i++)
	{
		if (A[i] == '-')cnt1++;
		if (A[i] == 'o')cnt2++;
		if (A[i] == 'o')
		{
			sum++;
			if (sum > max)
				max = sum;
		}
		else {
		
			sum = 0;

		}
	}
	if (cnt1==0||cnt2==0)
		cout << "-1" << '\n';
	else {
		cout << max << '\n';
	}
	return 0;
}

你可能感兴趣的:(算法)