回 帖 发 新 帖 刷新版面

主题:MOZ 大哥~~~~求教阿~~~

一、甲、乙、丙三个在今年的高考中,分别考取了北大、清华、复旦三所院校的数学系、地理系、历史系。现在已知道了下列情况。1、甲不在北大。2、乙不在清华。3、在北大的不在数学系。4、在清华的在地理系。5、乙不在历史系。请你判断甲、乙、丙三个分别在哪个院校哪个系。
    这道题可以解吧????

请 MOZ 大哥 详细讲解阿:1、解题的思路(算法思路?)
                        2、本人才接触编程想学好,所以就麻烦一下你
                               讲一下里面重要命令的作用。
                        3、通俗易懂阿~~
   不好意思 麻烦你了~~~~~~~~~~~~

回复列表 (共5个回复)

沙发

MY GOD 我都不会!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[em8]

板凳

呵呵,怎么找我来了,我这几天身体有点问题,差点没进厂大修.

这些题目都是条件判断了,
你可以利用循环(好像有个名词叫遍历)
把所有情况都检查一次,
看哪一种情况能符合所有条件的,就是答案了.

还有一种就是推理方法,
按照条件去推算下一个条件的位置,
但这有点特题特用了,不一定能适合特定题目.

我试试吧.看不明白看不清楚,你可以提问,我相信有很多人愿意回答你的问题的.

3 楼

for a=1 to 3
  if a<>1 then
     for b=1 to 3
       if b<>a and b<>2 then
          for c=1 to 3
            if c<>a and c<>b then
              for x=1 to 3
               if (a=1 and x<>1)or(a=2 and x=2)or(a=3)then
                for y=1 to 3
                 if (b=1 and y<>1)or(b=2 and y=2)or(b=3)then
                  if y<>3 and y<>x then
                   for z=1 to 3
                    if (c=1 and z<>1)or(c=2 and z=2)or(c=3)then
                     if z<>x and z<>y then
                      print a;b;c;x;y;z
                     endif
                    endif
                   next
                  endif
                 endif
                next
               endif
              next
            endif 
          next
       endif
     next
  endif 
next
在这里我用了很笨的方法,
把所有的条件都加进去了,
还加了很多重复的东西.
目的是希望能看得明白.
你先理解了其中的条件和作用,
你就能明白编程该怎样编了.

在上面用的是很笨的办法,
但对于这题目来说并无不妥,
因为它已经算是高效了,只是不太整洁,而且编写繁复.

4 楼

abc代表的是上哪个学校
xyz代表的是读哪一专业

想要追求书面的整洁,倒也是可以的.
只是理解上会有些周折.

cls
a$="123123"
do while a$ < "321321"
  if mid$(a$,1,1)<>"1" then   '甲不在北大
     if mid$(a$,2,1)<>"2" then   '乙不在清华
        if mid$(a$,instr(a$,"1")+3,1)<>"1" then  '在北大的不在数学系
           if mid$(a$,instr(a$,"2")+3,1)="2" then  '在清华的在地理系
              if mid$(a$,5,1)<>"3" then             '乙不在历史系
                 print a$
              endif
           endif
        endif
     endif
  endif
  a$=nexta$(a$)
loop
end

function nexta$(a$)
  for i&=val(a$)+9 to 321321 step 9
      b$=ltrim$(str$(i&))
      for j&=1 to 3
          if instr(left$(b$,3),chr$(48+j&))=0 then exit for
          if instr(4,b$,chr$(48+j&))=0 then exit for
      next
      if j&>3 then exit for
  next
  nexta$=b$
end function

5 楼

哇~~ 太感谢了。。。
 我一定会好好研究的~~

我来回复

您尚未登录,请登录后再回复。点此登录或注册