B. Homecoming:题目
思路:从后往前遍历就行了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> a((int)6e5);
vector<ll> b((int)6e5);
string str;
int main()
{int t;cin >> t;while (t--){int a, b, p;cin >> a >> b >> p;cin >> str;int n = str.length();int cou = 0;int res = n;int now = n - 2, i = n - 2;while (1){while (str[i] == str[now] && i >= 0)i--;if (i < 0)break;if (str[i + 1] == 'A'){if (p - a >= 0)p -= a;elsebreak;res = i + 2;}else{if (p - b >= 0)p -= b;elsebreak;res = i + 2;}now = i;}if (i == -1){if (str[0] == 'A'){if (p >= a)res = 1;}else{if (p >= b)res = 1;}}cout << res << endl;}
}