标签:span i++ with pre acm std code acm-icpc 相同
把这题的每个点分成两种情况看,如果是从这个点开始,0算作2,1算作1,如果是中间点或者是结束点,如果和前面的相同看作2,不相同看作1
#include <iostream> #include <string> #include <string.h> using namespace std; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int a, b; string str; cin >> str; int num = 0; long long sum = 0; for (int i = 0; i < str.size(); i++) { a = str[i] - ‘0‘; if (!a) a = 2; if (i) { if (str[i] == str[i - 1]) { b = 2; } else { b = 1; } } sum += a * (str.size() - i) + b * (str.size() - i) * num; num++; } cout << sum << endl; } return 0; }
标签:span i++ with pre acm std code acm-icpc 相同
原文地址:https://www.cnblogs.com/qq965921539/p/9657018.html