• Home
  • About
    • on Weekend photo

      on Weekend

      ๐™Ž๐™ฉ๐™ช๐™™๐™ฎ๐™ž๐™ฃ๐™œ

    • Learn More
    • Instagram
    • Github
  • Archive
    • All Posts
    • All Tags
    • All Categories
  • Categories
    • Problem Solving
    • TIL
    • Study
    • Etc
    • ํ•„์‚ฌ
  • Projects

[๋ฐฑ์ค€] 8958

04 Dec 2020

์ฝ”๋“œ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฌธ์ œ ํ™•์ธ

ํ’€์ด

๊ฐ„๋‹จํ•œ ๊ตฌํ˜„ ๋ฌธ์ œ๋กœ, ์—ฐ์†์œผ๋กœ O์ผ ๊ฒฝ์šฐ์—๋Š” ๋งค๋ฒˆ sum์— ํ˜„์žฌ count๋ฅผ ๋”ํ•˜๊ณ , count๋ฅผ 1 ์ฆ๊ฐ€์‹œํ‚ค๋˜ count์˜ ์‹œ์ž‘์ ์ด 1์ธ ์ ์„ ์œ ์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. X์ผ ๋•Œ์—๋Š” count๋ฅผ 1๋กœ ์ดˆ๊ธฐํ™”ํ•ด์ค๋‹ˆ๋‹ค.

์ฝ”๋“œ

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int ans;
	int T;
	cin >> T;
	while (T--) {
		ans = 0;
		string str = "";
		cin >> str;
		int tmp_score = 1;
		for (int i = 0; i < str.length(); i++)
		{
			if (str[i] == 'X') tmp_score = 1;
			else {
				ans += tmp_score;
				tmp_score++;
			}
		}
		cout << ans << endl;
	}

	return 0;
}



problem_solvingc++ Share Tweet +1