Skip to content

Instantly share code, notes, and snippets.

@WindAzure
Last active September 16, 2018 16:26
Show Gist options
  • Select an option

  • Save WindAzure/c8acd0f5715c960d16d4bac9c190eb02 to your computer and use it in GitHub Desktop.

Select an option

Save WindAzure/c8acd0f5715c960d16d4bac9c190eb02 to your computer and use it in GitHub Desktop.
UVa 1585
#include <stdio.h>
#include <string.h>
int main()
{
auto T = 0;
int dp[100] = { 0 };
char testResult[100];
scanf("%d", &T);
for (auto t = 0; t < T; t++)
{
scanf("%s", testResult);
auto strLen = strlen(testResult);
for (auto i = 0; i < strLen; i++)
{
dp[i] = (testResult[i] == 'O') ? 1 : 0;
}
auto result = 0;
for (auto i = 1; i < strLen; i++)
{
if (testResult[i] == 'O')
{
dp[i] += dp[i - 1];
result += dp[i];
}
}
printf("%d\n", result + dp[0]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment