回 帖 发 新 帖 刷新版面

主题:入门必做的题

1.  给定等式  A B C D E     其中每个字母代表一个数字,且不同数字对应不
                    D F G     同字母。编程求出这些数字并且打出这个数字的
             +      D F G     算术计算竖式。

             ───────

                X Y Z D E



  2. A、B、C、D、E五名学生有可能参加计算机竞赛,根据下列条件判断哪些
  人参加了竞赛:

   (1)A参加时,B也参加;

   (2)B和C只有一个人参加;

   (3)C和D或者都参加,或者都不参加;

   (4)D和E中至少有一个人参加;

   (5)如果E参加,那么A和D也都参加。



  3. 打印一个 N*N 的方阵,N为每边           N=15  打印出下面图形
 字符的个数(3<N<20), 要求最               TTTTTTTTTTTTTTT
 外一层为"T", 第二层为"J", 从第三层               TJJJJJJJJJJJJJT
 起每层依次打印数字 1,2,3,...                     TJ11111111111JT
 (右图以N为15为例)                           TJ12222222221JT
                                                  TJ12333333321JT
                                                  TJ12344444321JT
                                                  TJ12345554321JT
                                                  TJ12345654321JT
                                                  TJ12345554321JT
                                                  TJ12344444321JT
                                                  TJ12333333321JT
                                                  TJ12222222221JT
                                                  TJ11111111111JT
                                                  TJJJJJJJJJJJJJT
                                                  TTTTTTTTTTTTTTT



  4. 在N行N列的数阵中, 数K(1〈=K〈=N)在每行和每列中出现且仅
  出现一次,这样的数阵叫N阶拉丁方阵。例如下图就是一个五阶拉丁方阵。
  编一程序,从键盘输入N值后,打印出所有不同的N阶拉丁方阵,并统计个数。

        1  2  3  4  5
        2  3  4  5  1
        3  4  5  1  2
        4  5  1  2  3
        5  1  2  3  4


  5. 输入一个十进数,将其转换成 N 进制数(0<N<=16)。

回复列表 (共635个回复)

121 楼

To 117楼:
其实我们的答案都是错误的.
应该有n!*(n-1)!*..*2!*1!种排法.
http://rts.dec.ecnu.edu.cn/zsb/zsx/zsx09/zsx09a/zsx09a01/zsx09a012.htm

122 楼

To 113 楼:程序代码如下:
//利用3进制可以求n个球的好坏情况,你只要构造自己的唯一对应表 table[] 就行了.
//即每个球的编号对应一个三进制数,称量情况(即三进制数)只要转换为对应的球的编号就行了.下面是我构造的对应表(当然还有其他的):
/*
table[9]:
1:  0  1  1     4
2:  0 -1  1    -2
3:  1 -1  1     7
4:  1  0 -1     8
5:  1  1 -1    11
6:  -1 -1 -1  -13
7:  -1 0  0    -9
8:  -1 1  0    -6
*/
#include<iostream>
using namespace std;
int weight[9]={0};
int table[9]={0,4,-2,7,8,11,-13,-9,-6};
void HashSearch(const int (&table)[9],const int num)
{
    for(int i=1;i<9;i++)
        if(num==table[i])
            cout<<"第"<<i<<"个球重.\n";
        else if(num==-table[i])
            cout<<"第"<<i<<"个球轻.\n";
}
int Compare(int a,int b)
{
    return a>b?1:a==b?0:-1;
}
void main()
{
    int num,temp;//分别存放伪造硬币的号码和重量(1代表重,-1代表轻)
    cout<<"Please input the number of the fake coin:\t";
    cin>>num;
    cout<<"Please input the weight of the fake coin:\n\
(1 stands for heavy,-1 stands for light.)\t\t";
    cin>>temp;
    weight[num]=temp;
    int a=weight[3]+weight[4]+weight[5];
    int b=weight[6]+weight[7]+weight[8];
    cout<<"The first metage:\n   3,4,5 and 6,7,8   "<<Compare(a,b)<<endl;
    int sum=Compare(a,b)*9;
    a=weight[1]+weight[5]+weight[8];
    b=weight[2]+weight[3]+weight[6];
    cout<<"The second metage:\n   1,5,8 and 2,3,6   "<<Compare(a,b)<<endl;
    sum+=Compare(a,b)*3;
    a=weight[1]+weight[2]+weight[3];
    b=weight[4]+weight[5]+weight[6];
    cout<<"The third metage:\n   1,2,3 and 4,5,6   "<<Compare(a,b)<<endl;
    sum+=Compare(a,b);
    HashSearch(table,sum);
}

123 楼

To if007:
Everyone of us have the opportunity to make mistakes,but this does not mean that we are stupid.On the contrary, only when someone points out the mistakes we have made will we remember it for ever. Only when we are communicating with others and discussing the concept that is not easy to understand can we make progress continually.So don't worry about whether you are wrong or right,just make it.I think this is the most important.
"You are excellent!" ,remember it.

124 楼

呵呵,真是牛人辈出啊!

125 楼

要是有大答案就好了啊!

126 楼

哈,谢谢! 
你说得十分正确,好东西偶都是全盘接收的.
顺带一说,偶赞赏和喜欢你的态度, 实事求是!

127 楼

激发吾热情

128 楼

猴子选大王1:请大侠帮忙优化、精简。
#include"iostream.h"
#define M 10//共有M个猴子。
#define N 3//数到N者出局。
void main()
{
    int i,l,p,t;
    char mon[M];//例10只猴子。
    i=1;
    l=0;
    p=0;//当前元素。
    while(l!=M)
    {
        if(mon[p]!='#')
            if(i!=N)
            {
                i++;
                p=++p%M;
            }
            else
            {
                mon[p]='#';
                t=p;
                cout<<t+1<<"号猴子出局。"<<endl;
                p=++p%M;
                l++;
                i=1;
            }
        else
            p=++p%M;


    };
    cout<<t+1<<"号猴子是大王!"<<endl;
}


129 楼

TO 123楼:
      You are right!That is what I am going to say.Don't worry,just do it.

130 楼

可以告诉我是南京大学的哪个牛人吗?真想当面向他请教下,我是南京大学旁边的东南大学的~~~~~~~~~~~~~~~~~

我来回复

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