From 4fa9af73d15440a40f95f1ad390cb959f480747c Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 5 May 2022 23:10:05 +0800 Subject: [PATCH] C - Detective Task https://codeforces.com/contest/1675/submission/155959148 --- Codeforces/1675/C/C.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Codeforces/1675/C/C.cpp diff --git a/Codeforces/1675/C/C.cpp b/Codeforces/1675/C/C.cpp new file mode 100644 index 00000000..5183527d --- /dev/null +++ b/Codeforces/1675/C/C.cpp @@ -0,0 +1,41 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2e5 + 5; + +int t, sum[N][2], ans; +std::string s; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> t; + + while (t--) { + ans = 0; + + cin >> s; + + for (int i = 0; i < s.size(); i++) { + if (i) { + sum[i][0] = sum[i - 1][0] + (s[i] == '0'); + sum[i][1] = sum[i - 1][1] + (s[i] == '1'); + } else { + sum[i][0] = s[i] == '0'; + sum[i][1] = s[i] == '1'; + } + } + + for (int i = 0; i < s.size(); i++) { + ans += (sum[i][0] - (s[i] == '0')) == 0 && (sum[s.size() - 1][1] == sum[i][1]); + } + + cout << ans << endl; + } + + return 0; +}