1103 - Ancient Messages

本文介绍了一款用于识别古埃及象形文字的程序,该程序能够从图像中识别出六种特定的象形字符,并将其转换为现代字符表示。输入图像由十六进制编码的黑白像素组成,程序通过特定的算法解析这些象形文字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In order to understand early civilizations, archaeologists often study texts written in ancient languages. One such language, used in Egypt more than 3000 years ago, is based on characters called hieroglyphs. Figure C.1 shows six hieroglyphs and their names. In this problem, you will write a program to recognize these six characters.

\epsfbox{p5130a.eps}

Figure C.1: Six hieroglyphs

Input 

The input consists of several test cases, each of which describes an image containing one or more hieroglyphs chosen from among those shown in Figure C.1. The image is given in the form of a series of horizontal scan lines consisting of black pixels (represented by 1) and white pixels (represented by 0). In the input data, each scan line is encoded in hexadecimal notation. For example, the sequence of eight pixels10011100 (one black pixel, followed by two white pixels, and so on) would be represented in hexadecimal notation as 9c. Only digits and lowercase letters a through f are used in the hexadecimal encoding. The first line of each test case contains two integers, H and WH (0 < H$ \le$200) is the number of scan lines in the image. W (0 < W$ \le$50) is the number of hexadecimal characters in each line. The next H lines contain the hexadecimal characters of the image, working from top to bottom. Input images conform to the following rules:


  • The image contains only hieroglyphs shown in Figure C.1.
  • Each image contains at least one valid hieroglyph.
  • Each black pixel in the image is part of a valid hieroglyph.
  • Each hieroglyph consists of a connected set of black pixels and each black pixel has at least one other black pixel on its top, bottom, left, or right side.
  • The hieroglyphs do not touch and no hieroglyph is inside another hieroglyph.
  • Two black pixels that touch diagonally will always have a common touching black pixel.
  • The hieroglyphs may be distorted but each has a shape that is topologically equivalent to one of the symbols in Figure C.1. (Two figures are topologically equivalent if each can be transformed into the other by stretching without tearing.)


The last test case is followed by a line containing two zeros.

Output 

For each test case, display its case number followed by a string containing one character for each hieroglyph recognized in the image, using the following code:


Ankh: A 
Wedjat: J 
Djed: D 
Scarab: S 
Was: W 
Akhet: K


In each output string, print the codes in alphabetic order. Follow the format of the sample output.

The sample input contains descriptions of test cases shown in Figures C.2 and C.3. Due to space constraints not all of the sample input can be shown on this page.


$\textstyle \parbox{.5\textwidth}{\begin{center}\mbox{}\epsfbox{p5130b.eps}\parFigure C.2: AKW\end{center}}$$\textstyle \parbox{.49\textwidth}{\begin{center}\mbox{}\epsfbox{p5130c.eps}\parFigure C.3: AAAAA\end{center}}$

Sample Input 

100 25
0000000000000000000000000
0000000000000000000000000
...(50 lines omitted)...
00001fe0000000000007c0000
00003fe0000000000007c0000
...(44 lines omitted)...
0000000000000000000000000
0000000000000000000000000
150 38
00000000000000000000000000000000000000
00000000000000000000000000000000000000
...(75 lines omitted)...
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
...(69 lines omitted)...
00000000000000000000000000000000000000
00000000000000000000000000000000000000
0 0

Sample Output 

Case 1: AKW
Case 2: AAAAA




#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<string>
#include<stdlib.h>
using namespace std;
#define PB push_back
int N,M,A[209][209];
bool vis[209][209];
int belong[209][209];
int b[209*209];

void Init()
{
	for(int i=0;i<=N+1;i++)
		for(int j=0;j<=M*4+1;j++)
			A[i][j]=0;
	for(int i=1;i<=N;i++)
		for(int j=1,jj=1;j<=M;j++,jj+=4)
		{
			char r;
			cin>>r;
			int x;
			if(r>='a'&&r<='z')
				x=10+r-'a';
			else
				x=r-'0';
			A[i][jj]=(x/8)%2;
			A[i][jj+1]=(x/4)%2;
			A[i][jj+2]=(x/2)%2;
			A[i][jj+3]=(x/1)%2;
		}
	M*=4;
}

void Dfs0(int x,int y,int c)
{
	if(x<0||y<0||x>N+1||y>M+1)
		return ;
	if(vis[x][y])
		return ;
	if(A[x][y]!=0)
		return;
	vis[x][y]=true;
	belong[x][y]=c;
	Dfs0(x+1,y,c);
	Dfs0(x-1,y,c);
	Dfs0(x,y+1,c);
	Dfs0(x,y-1,c);
}

int Dfs1(int x,int y,int vt)
{
	int ret=0;
	if(x<0||y<0||x>N+1||y>M+1)
		return 0;
	if(vis[x][y])
		return 0;
	if(A[x][y]!=1)
	{
		if(b[belong[x][y]]!=vt)
			ret++;
		b[belong[x][y]]=vt;
		return ret;
	}
	vis[x][y]=true;
	ret+=Dfs1(x+1,y,vt);
	ret+=Dfs1(x-1,y,vt);
	ret+=Dfs1(x,y+1,vt);
	ret+=Dfs1(x,y-1,vt);
	return ret;
}

void Solve()
{
	for(int i=0;i<=N+1;i++)
		for(int j=0;j<=M+1;j++)
			vis[i][j]=false;
	int SpaceNum=0;
	for(int i=0;i<=N+1;i++)
		for(int j=0;j<=M+1;j++)
			if(A[i][j]==0)
				Dfs0(i,j,++SpaceNum);
	for(int i=0;i<=N+1;i++)
		for(int j=0;j<=M+1;j++)
			vis[i][j]=false;
	vector<char> Answer;
	Answer.clear();
	int vt=0;
	for(int i=1;i<=SpaceNum;i++)
		b[i]=-1;
	for(int i=0;i<=N+1;i++)
		for(int j=0;j<=M+1;j++)
			if(A[i][j]==1)
			{
				int t=Dfs1(i,j,vt++);
				if(t==1)
					Answer.PB('W');
				if(t==2)
					Answer.PB('A');
				if(t==3)
					Answer.PB('K');
				if(t==4)
					Answer.PB('J');
				if(t==5)
					Answer.PB('S');
				if(t==6)
					Answer.PB('D');
			}
	sort(Answer.begin(),Answer.end());
	for(int i=0;i<Answer.size();i++)
		cout<<Answer[i];
	cout<<"\n";
}


int main()
{
	int Case=0;
	while(cin>>N>>M&&(N||M))
	{
		Init();
		cout<<"Case "<<++Case<<": ";
		Solve();
	}
	return 0;
}


报错了: FAILED [100%] test_len.py:9 (TestWms.test_02) self = <case.test_len.TestWms object at 0x000002902917B2B0> def test_02(self): > datas = xfile.read(r"C:\Users\shuohan\Desktop\gaoliu-1\仓库删除模块接口用例.xlsx").excel_to_dict(sheet=1) test_len.py:11: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ..\..\myvenv\lib\site-packages\xToolkit\xfile\dispose\dispose.py:67: in excel_to_dict workbook = xlrd.open_workbook(excel_file) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ filename = 'C:\\Users\\shuohan\\Desktop\\gaoliu-1\\仓库删除模块接口用例.xlsx' logfile = <_io.TextIOWrapper name='<tempfile._TemporaryFileWrapper object at 0x00000290000E2940>' mode='r+' encoding='utf-8'> verbosity = 0, use_mmap = True, file_contents = None, encoding_override = None formatting_info = False, on_demand = False, ragged_rows = False ignore_workbook_corruption = False def open_workbook(filename=None, logfile=sys.stdout, verbosity=0, use_mmap=True, file_contents=None, encoding_override=None, formatting_info=False, on_demand=False, ragged_rows=False, ignore_workbook_corruption=False ): """ Open a spreadsheet file for data extraction. :param filename: The path to the spreadsheet file to be opened. :param logfile: An open file to which messages and diagnostics are written. :param verbosity: Increases the volume of trace material written to the logfile. :param use_mmap: Whether to use the mmap module is determined heuristically. Use this arg to override the result. Current heuristic: mmap is used if it exists. :param file_contents: A string or an :class:`mmap.mmap` object or some other behave-alike object. If ``file_contents`` is supplied, ``filename`` will not be used, except (possibly) in messages. :param encoding_override: Used to overcome missing or bad codepage information in older-version files. See :doc:`unicode`. :param formatting_info: The default is ``False``, which saves memory. In this case, "Blank" cells, which are those with their own formatting information but no data, are treated as empty by ignoring the file's ``BLANK`` and ``MULBLANK`` records. This cuts off any bottom or right "margin" of rows of empty or blank cells. Only :meth:`~xlrd.sheet.Sheet.cell_value` and :meth:`~xlrd.sheet.Sheet.cell_type` are available. When ``True``, formatting information will be read from the spreadsheet file. This provides all cells, including empty and blank cells. Formatting information is available for each cell. Note that this will raise a NotImplementedError when used with an xlsx file. :param on_demand: Governs whether sheets are all loaded initially or when demanded by the caller. See :doc:`on_demand`. :param ragged_rows: The default of ``False`` means all rows are padded out with empty cells so that all rows have the same size as found in :attr:`~xlrd.sheet.Sheet.ncols`. ``True`` means that there are no empty cells at the ends of rows. This can result in substantial memory savings if rows are of widely varying sizes. See also the :meth:`~xlrd.sheet.Sheet.row_len` method. :param ignore_workbook_corruption: This option allows to read corrupted workbooks. When ``False`` you may face CompDocError: Workbook corruption. When ``True`` that exception will be ignored. :returns: An instance of the :class:`~xlrd.book.Book` class. """ file_format = inspect_format(filename, file_contents) # We have to let unknown file formats pass through here, as some ancient # files that xlrd can parse don't start with the expected signature. if file_format and file_format != 'xls': > raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported') E xlrd.biffh.XLRDError: Excel xlsx file; not supported ..\..\myvenv\lib\site-packages\xlrd\__init__.py:170: XLRDError
最新发布
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值