poj3095

简单的模拟

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<cmath>
using namespace std;

#define maxn 100

string st;
int n;

bool left(int a)
{
for (int i = a - 1; i >= 0; i--)
{
if (st[i] == '|' || st[i] == '\\' || st[i] == '/')
return false;
if (st[i] == '.')
return true;
}
return true;
}

bool right(int a)
{
for (int i = a + 1; i < n; i++)
{
if (st[i] == '|' || st[i] == '\\' || st[i] == '/')
return false;
if (st[i] == '.')
return true;
}
return true;
}

int main()
{
//freopen("D:\\t.txt", "r", stdin);
while (getline(cin, st) && st != "#")
{
n
= st.length();
int sum = 0;
for (int i = 0; i < n; i++)
{
if (st[i] == '_')
{
sum
+= 0;
continue;
}
if (st[i] == '.')
{
sum
+= 100;
continue;
}
if (st[i] == '/')
{
sum
+= left(i) * 100;
continue;
}
if (st[i] == '\\')
{
sum
+= right(i) * 100;
continue;
}
if (st[i] == '|')
{
sum
+= left(i) * 50 + right(i) * 50;
continue;
}
}
cout
<< int(sum / double(n)) << endl;
}
return 0;
}
posted @ 2011-03-13 12:06  金海峰  阅读(182)  评论(0编辑  收藏  举报