[代码实验]PiZYDS Isomorphic Calculators Beta1 同分异构计算器

前言

PiZYDS Isomorphic Calculators Beta1 同分异构计算器(Unsucceed)

这是Pillars在看完化学试卷答案后的感慨,写了这个Pascal程序。

很遗憾,这是一个尝试的版本,基本上就是搜索枚举,但会产生很多重复,浪费大量时间资源。该思路已经放弃。

开源代码

《[代码实验]PiZYDS Isomorphic Calculators Beta1 同分异构计算器》

https://github.com/PillarsZhang/PiZYDS-Isomorphic-Calculators-Beta1

《[代码实验]PiZYDS Isomorphic Calculators Beta1 同分异构计算器》

http://git.oschina.net/PillarsZhang/PiZYDS-Isomorphic-Calculators-Beta1

在线预览

program PiZYDS_Isomorphic_Calculators;
var
	mf,outinfor:string;
	lenmf,i,j,amfs,num:longint;
	lastm:char;
	printrq:boolean;
    amf:array[0..100] of char;
    ckey:array['a'..'z'] of longint;
    bmf:array[0..100,0..100] of longint;
    //amf 把结构简式或者分子式展开来,比如ch3cho->chhhcho
    //amfs展开的式子里有几个原子
    //ckey每个原子的最好饱和价键
    //bmf目前的价键
   

procedure settings();
begin
    ckey['c']:=4;
    ckey['h']:=1;
    ckey['o']:=2;  
    printrq:=false; 
    num:=0;
end;

procedure print();
var
 i,j:longint;
begin
 writeln;
 write('  ');
 for j:=1 to amfs do write(amf[j],' ');
 writeln;
 
for i:=1 to amfs do
 begin
  write(amf[i],' ');
  for j:=1 to amfs do write(bmf[i,j],' ');
  writeln;
 //md输出都那么累
  end; 
 end;

function test(ck:longint):longint;
//test=0不够饱
//test=1刚刚好
//test=2要炸了
 var
   i,j,sum:longint;
 begin
   //这张bmf二维表有点烧脑所以全算进去吧
   sum:=0;
   for i:=1 to amfs do
    sum:=sum+bmf[i,ck];
   
   for j:=1 to amfs do
    sum:=sum+bmf[ck,j];
    
    if sum<ckey[amf[ck]] then test:=0
      else
      if sum=ckey[amf[ck]] then test:=1
       else test:=2;
       
   outinfor:=outinfor+amf[ck]+':'+chr(ord('0')+sum)+' ';
end;
 

procedure find(bi,bj:longint);
 var
  i,j:longint;
  bool,bool2:boolean;
  
  begin 
  //先来看看满不满足
  bool:=true; bool2:=true;
  outinfor:='';
  for i:=1 to amfs do
   begin
     if test(i)<>1 then bool:=false;
     //if test(i)>1 then bool2:=false;
   end;
  //if not(bool2) then exit;
  //后来想想写了没什么用,我指那个bool2
  
  //如果bool为true,太好了,找到了
  if bool then
  begin
   inc(num);
   if printrq then
    begin
     print();
     writeln(outinfor);
     writeln('This one OK!')
    end;
   //测试用的
   exit;
   //已经OK了,跳出这个尝试
  end;
   //readln; //调试用,要不然太汹涌
  
  for i:=bi to amfs do
    for j:=bj to amfs do
     begin
      inc(bmf[i,j]);
      if (test(i)<=1) and (test(j)<=1) then
      find(i,j);
      dec(bmf[i,j]);
     end;
   end;
   
   
begin    
   settings();
	readln(mf);
	writeln('Calculting ',mf);
	lenmf:=length(mf);
	//fillchar(amf,sizeof(amf),'');
	//fillchar(bmf,sizeof(bmf),0);
	//安卓的Pascal好像不只是sizeof...
	amfs:=0;
	for i:=1 to lenmf do
	 begin
		if (mf[i]>='a') and (mf[i]<='z') then
		begin
		  lastm:=mf[i];
		  inc(amfs);
		  amf[amfs]:=lastm;
	    end;
      
       if (mf[i]>='2') and (mf[i]<='9') then
        for j:=2 to (ord(mf[i])-ord('0')) do
        begin
         inc(amfs);
         amf[amfs]:=lastm;
         end;
    end;
     //Read End
     
   write('Spread Result: ');
   for i:=1 to amfs do write(amf[i]);
   writeln;
   //又是一个测试块
     Find(1,2);
   //原本想搞个开始找的坐标后来搞不定还不如直接去重
     writeln('Kinds: ',num);
  end.
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注