Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

其实这题并不难,但要注意几种情况(附代码)

Posted by ly50247 at 2009-07-01 17:50:50 on Problem 3095
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
using namespace std;

char data[120];
int main()
{
	while (true)
	{
		scanf("%s", data);
		if (data[0] == '#')
			break;
		
		int len = strlen(data);
		double sum = 0;
		for (int i=0; i < len; i++)
		{
			if (data[i] == '.')
				sum += 100;
			else if (data[i] == '_')
				continue;
			else if (data[i] == '/')
			{
				if (i == 0)
					sum += 100;
				for (int j=i-1; j >=0; j--)
				{
					if (data[j] == '.')
					{
						sum += 100;
						break;
					}
					else if (data[j] == '|' || data[j] == '\\')
						break;
					else if (j == 0)
						sum += 100;
				}
				
			}
			else if (data[i] == '\\')
			{
				if (i == len-1)
					sum += 100;
				for (int j=i+1; j < len; j++)
				{
					if (data[j] == '.')
					{
						sum += 100;
						break;
					}
					else if (data[j] == '|' || data[j] == '/')
						break;
					else if (j == len-1)
						sum += 100;
				}				
			}
			else if (data[i] == '|')
			{
				if (i == 0 )
					sum += 50;
				if (i == len - 1)
					sum += 50;
				for (int j=i-1; j >=0; j--)
				{
					if (data[j] == '.')
					{
						sum += 50;
						break;
					}
					else if (data[j] == '|' || data[j] == '\\')
						break;
					else if (j == 0)
						sum += 50;
				}
				
				for (int j=i+1; j < len; j++)
				{
					if (data[j] == '.')
					{
						sum += 50;
						break;
					}
					else if (data[j] == '|' || data[j] == '/')
						break;
					else if (j == len-1)
						sum += 50;
				}	
							
			}
		}
		sum /= len;
		printf("%d\n", (int)sum);
	}



	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator