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
<think>好的,我现在需要解决用户遇到的这个错误。用户在使用Python的xlrd库读取Excel文件时,遇到了XLRDError,提示“Excel xlsx file; not supported”。首先,我应该回忆一下xlrd库的版本变化。 记得以前xlrd是支持xlsx格式的,但后来在某个版本之后,可能出于安全考虑,移除了对xlsx的支持。现在用户遇到这个错误,很可能是因为他们的xlrd版本过高,比如1.2.0之后,不再支持xlsx文件。 接下来,我需要确认用户的代码是否正确。用户使用的是xfile.read方法,传入了一个xlsx文件的路径,然后调用excel_to_dict方法。错误发生在xlrd.open_workbook这一步,说明问题出在xlrd库无法处理xlsx文件。 解决方案可能有几个方向。首先,建议用户降级xlrd到1.2.0之前的版本,比如1.1.0,这样可能恢复对xlsx的支持。不过,降级库版本可能带来其他兼容性问题,需要用户权衡。 另一个方法是改用其他支持xlsx的库,比如openpyxl或者pandas。例如,pandas的read_excel函数默认使用openpyxl来处理xlsx文件,这可能更可靠。用户需要安装openpyxl,并修改代码,使用pandas来读取Excel文件,然后转换为字典格式。 此外,检查用户代码中的文件路径是否正确,是否有权限问题,或者文件是否损坏,也是必要的步骤。不过根据错误信息,问题更可能出在库的支持上,而不是文件本身。 最后,可能还需要提醒用户,如果使用的是xfile这个第三方库,可能需要查看其文档,确认是否支持xlsx文件,或者是否有其他配置需要调整。如果xfile依赖于xlrd,那么可能需要结合上述解决方案进行调整。 总结下来,用户需要安装合适的库,并调整读取Excel文件的方式,或者降级xlrd版本。同时,确保文件路径正确,文件未被占用或损坏。 </think> 这个错误是由于使用的 `xlrd` 库版本过高(≥1.2.0),不再支持 `.xlsx` 格式文件。以下是解决方案: --- ### 解决方案: 1. **降级 `xlrd` 到 1.1.0 或更低版本**: ```bash pip uninstall xlrd pip install xlrd==1.1.0 ``` 这会恢复对 `.xlsx` 文件的支持。 2. **改用 `openpyxl` 库**(推荐): ```python # 安装 openpyxl pip install openpyxl # 修改代码,使用 openpyxl 读取 .xlsx 文件 from openpyxl import load_workbook def excel_to_dict(file_path, sheet_index=0): wb = load_workbook(file_path) sheet = wb.worksheets[sheet_index] data = [] for row in sheet.iter_rows(values_only=True): data.append(row) return data ``` 3. **使用 `pandas` 替代**: ```python import pandas as pd def excel_to_dict(file_path, sheet_index=0): df = pd.read_excel(file_path, sheet_name=sheet_index, engine='openpyxl') return df.to_dict('records') ``` --- ### 注意事项: - 确保文件路径正确且文件未被其他程序占用。 - 如果使用 `xfile` 库,检查其是否依赖 `xlrd`,可能需要调整代码或联系库作者。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值