跳到正文

个人记录

我的世界红石电路

xu_zhihao约 6 分钟
原文
文章信息与版本

文章信息

发布
2023年10月19日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 6 分钟
获赞
1

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
char a[110][110];
int i=0,j=0;
int main()
{
	int n,m;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		scanf("%s",a[i]);//输入电路图; 
	}
	int switch_cnt=0;//寻找有多少个开关;
	int x=0,y=0;
	for(i=0;i<n;i++)
	{
	    for(j=0;j<m;j++)
		{
		    if(a[i][j]=='T' || a[i][j]=='F')
			{
			    switch_cnt++;
				x=j;
				y=i;	
			}	
		}	
	}
	if(switch_cnt==0)
	{
		cout<<"false";
	}
	if(switch_cnt==1)//单向红石电路情况;
	{
	    //string s=a[y][x];
	    int g=0;
	    for(int i=x+1;i<m;i++)
	    {
	    	if(a[y][i]=='-')
	    	{
				g++;
				if(g<13 && a[y][i-1]=='T')
				{
				    a[y][i]='T';	
				}
				else
				{
				    a[y][i]='F';	
				}	
			}
			else if(a[y][i]=='_')
			{
				if(a[y][i-1]=='T')
				{
					a[y][i]='T';
					
				}
				else
				{
					a[y][i]='F';
				}
				g=0;
			}
			else if(a[y][i]=='i')
			{
				if(i==0)
				{
					a[y][i]='F';
				}
				else if(a[y][i-1]=='T')
				{
					a[y][i]='F';
				}
				else
				{
					a[y][i]='T';
				}
			}
			else if(a[y][i]=='.')
			{
				cout<<"false";
				return 0;
			}
			else if(a[y][i]=='#')
			{
				if(i==0)
				{
				    cout<<"false";
					return 0;	
				}
				if(a[y][i-1]=='T')
				{
					cout<<"true";
					return 0;
				}
				else
				{
					cout<<"false";
					return 0;
				}
			}
		}
	}
	if(switch_cnt==2)
	{
	    int g=0;
		int y2=y; 
		for(i=x+1;i<m;i++)
	    {
	    	if(a[y][i]=='-')
	    	{
				g++;
				if(g<13 && (a[y][i-1]=='T' || a[y+1][i]=='T'))
				{
				    a[y][i]='T';	
				}
				else
				{
				    a[y][i]='F';	
				}	
			}
			else if(a[y][i]=='_')
			{
				if(a[y][i-1]=='T' || a[y-1][i]=='T')
				{
					a[y][i]='T';
					g=0;
				}
				else
				{
					a[y][i]='F';
				}
				g=0;
			}
			else if(a[y][i]=='i')
			{
				if(a[y][i-1]=='T' || a[y-1][i]=='T')
				{
					a[y][i]='F';
				}
				else
				{
					a[y][i]='T';
				}
			}
			else if(a[y][i]=='.')
			{
				y=y-1;
				i-=2;
			}
			else if(a[y][i]=='#')
			{
				if(i==0)
				{
				    break;	
				}
				if(a[y][i-1]=='T' || a[y-1][i]=='T')
				{
					cout<<"true";
					return 0;
				}
				else
				{
					break;
				}
			}
			
			
		}
		g=0;
		int x2=0;
		y2-=2; 
		for(i=0;i<m;i++)
		{
			if(a[y2][i]=='F' || a[y2][i]=='T')
			{
				x2=i;
				break;
			}
		}
		cout<<x2;
		for(i=x2+1;i<m;i++)
	    {
	    	if(a[y2][i]=='-')
	    	{
				g++;
				if(g<13 && (a[y2][i-1]=='T' || a[y2-1][i]=='T'))
				{
				    a[y2][i]='T';	
				}
				else
				{
				    a[y2][i]='F';	
				}	
			}
			else if(a[y2][i]=='_')
			{
				if(a[y2][i-1]=='T' || a[y2+1][i]=='T')
				{
					a[y2][i]='T';
					g=0;
				}
				else
				{
					a[y2][i]='F';
				}
				g=0;
			}
			else if(a[y2][i]=='i')
			{
				if(a[y2][i-1]=='T' || a[y2+1][i]=='T')
				{
					a[y2][i]='F';
				}
				else
				{
					a[y2][i]='T';
				}
			}
			else if(a[y2][i]=='.')
			{
				y2=y2+1;
				i-=2;
				
			}
			else if(a[y2][i]=='#')
			{
				if(i==0)
				{
				    cout<<"false";
					return 0;	
				}
				if(a[y2][i-1]=='T' || a[y2+1][i]=='T')
				{
					cout<<"true";
					return 0;
				}
				else
				{
					cout<<"false";
					return 0;
				}
			}
			
		}
	}
	//return 0; 
}
原文
存档评论1 条抓取于