UVA 1641 POJ 4022 ASCII Area


统计斜杠出现了奇数次还是偶数次


点击打开链接

Long time ago, most of PCs were equipped with video cards that worked only in text mode. If theprogrammer wanted to show a picture on a screen, he had to use pseudographics or ASCII art like this:^..^(OO)/ \()()In this problem you are given a polygon, drawn using ASCII art. Your task is to calculate its area.The picture is formed using characters ‘.’, ‘\’, and ‘/’. Each character represents a unit square of thepicture. Character ‘.’ represents an empty square, character ‘/’ — a square with a segment from thelower left corner to the upper right corner, and character ‘\’ — a square with a segment from the upperleft corner to the lower right corner./\/\\../.\.\..\/InputThe first line of the input file contains integer numbers h and w (2 ≤ h, w ≤ 100) — height and width ofthe picture. Next h lines contain w characters each — the picture drawn using ASCII art.It is guaranteed that the picture contains exactly one polygon without self-intersections and self-touches.OutputPrint to the output file one integer number — the area of the polygon.Sample input and outputascii.in ascii.out4 4/\/\\../.\.\..\/8Page 1 of 16ACM ICPC 2011–2012, Northeastern European R


/* ***********************************************
Author        :CKboss
Created Time  :2015年02月02日 星期一 10时27分48秒
File Name     :POJ4022.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

int h,w;
char mp[200][200];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	
	while(scanf("%d%d",&h,&w)!=EOF)
	{
		memset(mp,0,sizeof(mp));
		for(int i=0;i<h;i++)
		{
			scanf("%s",mp[i]);
		}
		int area = 0;
		for(int i=0;i<h;i++)
		{
			int temp = 0;
			for(int j=0;j<w;j++)
			{
				if(mp[i][j]=='\\'||mp[i][j]=='/') 
				{
					temp++; area+=1;
				}
				else if(mp[i][j]=='.')
				{
					if(temp%2) area+=2;
				}
			}
		}
		printf("%d\n",area/2);
	}
    
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值