ZOJ 1589 Professor John

本文探讨了在编程中如何通过引入记录数组mp2来简化处理字符串数组的任务,特别是涉及字符映射和矩阵操作的问题。文章详细介绍了算法的实现过程,并通过实例展示了效率提升的效果。

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

加一个记录数组mp2简单很多,不然用vector<string>加入后排序输出

#include<iostream>
#include<cstdio>
#include<string.h>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

const int N=105;
char str[4];
int mp[28][28],mp2[28][28];
int main(){
	int tt,n,t;
	for(cin>>tt,t=1;t<=tt;t++){
		cin>>n;
		memset(mp,0,sizeof mp);
		memset(mp2,0,sizeof mp2);
		while(n--){
			scanf("%s",str);
			int x=str[0]-'A',y=str[2]-'A';
			if(str[1]=='<')
				mp[x][y]=mp2[x][y]=1;
			else
				mp[y][x]=mp2[y][x]=1;
		}
		for(int k=0;k<26;k++){
			for(int i=0;i<26;i++)
				for(int j=0;j<26;j++)
					if(mp[i][k]&&mp[k][j])
						mp[i][j]=1;
		}
		printf("Case %d:\n",t);
		for(int i=0;i<26;i++)
			for(int j=0;j<26;j++){
				if(mp[i][j]!=mp2[i][j])
					printf("%c<%c\n",i+'A',j+'A'),n++;
			}
		if(n==-1)
			printf("NONE\n");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值