idiom.pl

来自「采用复杂数据结构完成成语接龙」· PL 代码 · 共 81 行

PL
81
字号
LoadIdiom("list",\@IdiomInfo);
GenLinkedIdiom(\@IdiomInfo,\%HashLinkedIdiom);
LinkedIdiom(\%HashLinkedIdiom);
	            

sub LinkedIdiom
{
	my ($RefHashLinkedIdiom)=@_;
	($MachineIdiom)=keys %{$RefHashLinkedIdiom};
	print "Machine:$MachineIdiom\nPls:";
	while(1){
		$UserIdiom=<stdin>;
		chomp($UserIdiom);
		$RefLinkedIdiom=$RefHashLinkedIdiom->{$MachineIdiom};
		if ( defined ${$RefLinkedIdiom}{$UserIdiom}){
			print "OK!\n";
		}else{
			@AllAnswer=keys %{$RefLinkedIdiom};
			if ( @AllAnswer == 0 ){
				last;
			}
			$no=0;
			print "All Answer:pls select one by ID:\n";
	
			foreach (@AllAnswer){
				print "$no:$_ ";
				$no++;
			}
			print "\n";
			$UserIdiom=<stdin>;
			$UserIdiom=$AllAnswer[$UserIdiom];
			print "you select:$UserIdiom\n";
		}
		$RefLinkedIdiom=$RefHashLinkedIdiom->{$UserIdiom};
		@AllAnswer=keys %{$RefLinkedIdiom};
		if ( @AllAnswer == 0 ){
			last;
		}
		($MachineIdiom)=@AllAnswer;
		print "Machine:$MachineIdiom\nPls:";
	
  }
	
}

sub GenLinkedIdiom
{
	my ($RefIdiomInfo,$RefHashLInedIdiom)=@_;
	foreach $Ref3Ele(@{$RefIdiomInfo}){
		$Idiom1=${$Ref3Ele}[0];
		$LastPY1=${$Ref3Ele}[2];
		foreach $Ref3Ele(@{$RefIdiomInfo}){
			$Idiom2=${$Ref3Ele}[0];
			$FirstPY2=${$Ref3Ele}[1];
			if ( $LastPY1 eq $FirstPY2 ){
				${${$RefHashLInedIdiom}{$Idiom1}}{$Idiom2}=1;
			}	
		}	
	}

}

sub LoadIdiom
{
	my($File,$RefIdiomPhrase)=@_;
	open(In,"$File");
	while(<In>){
		chomp;
		if (/^(\S+) ([^_]+).*_([^_]+)$/){
			my @PhraseInfo=();
			push(@PhraseInfo,$1);
			push(@PhraseInfo,$2);
			push(@PhraseInfo,$3);
			push(@$RefIdiomPhrase,\@PhraseInfo);
		}
		
	}
	close(In);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?