旮旯胡同吧 关注:33贴子:4,096

【贰零壹柒丶胡同°】0615嘘

只看楼主收藏回复

这是一个正经的帖子


来自Android客户端1楼2017-06-15 23:06回复
    插♀入♂


    IP属地:江苏来自Android客户端2楼2017-06-15 23:11
    收起回复
      /********计算圆的面积********/
      #include<iostream>
      using namespace std;
      int main()
      {
      const double pi = 3.14;
      double r;
      cin >> r;
      cout << r*r*3.14 << endl;
      return 0;
      }
      /********输入10个数,让他们逆序输出********/
      #include<iostream>
      using namespace std;
      void swap(int &a, int &b)//交换两个数
      {
      int temp;
      temp = a;
      a = b;
      b = temp;
      }
      void reserve(int *a)
      {
      for (int i = 0; i <= 4; i++)
      swap(a[i], a[9 - i]);//最后一位和第一位交换
      }
      int main()
      {
      int a[10];
      for (int i = 0; i < 10; i++)//输入
      cin >> a[i];
      reserve(a);
      for (int i = 0; i < 10; i++)//输出
      {
      cout << a[i];
      if (i != 9)//最后一位的后面是没有空格的
      cout << " ";
      }
      cout << endl;//换个行吧~
      return 0;
      }
      //注意,这道题其实不需要这么做;各位可以选择直接逆序输出,而不用这样逆序
      /********找出限定范围内的盈数个数********/
      /*第一步:找出一个数K所有的真约数
      第二步:判断这个数和真约数之和的大小
      第三步:判断这个数是不是真约数
      第四步:找出一个数K+1所有的真约数
      PS:这里就开始递归了~重复工作交给计算机去做吧*/
      #include<iostream>
      using namespace std;
      bool judge(int a)//判断一个数是否为盈数的函数
      {
      int sum = 0;//真约数之和就是sum
      for (int i = 1; i < a; i++)//0不是任何一个数的真约数,那么就不理它啦;而a不是a的真约数,出于方便,终止循环的条件这里就是i=a了
      {
      if (a%i == 0)//i能整除a,那么i就是a的一个真约数;注意“==”不要写成“=”
      {
      sum += i;//加上这个真约数~
      }
      }
      if (sum > a)//判断是不是盈数
      return true;//是,则返回真
      else
      return false;//否,则返回假
      }
      int main()
      {
      int m;
      int n = 0;//n是记录盈数个数的
      cin >> m;
      for (int i = 0; i <= m; i++)
      {
      if (judge(i))//判断i是不是盈数
      n++;
      }
      cout << n<<endl;
      return 0;
      }
      /*****************找出限定范围内的完数个数*****************/
      /*注:这道题和盈数的那道题很相似,我就偷懒复制粘贴了一大段*/
      #include<iostream>
      using namespace std;
      bool judge(int a)//判断一个数是否为完数的函数
      {
      int sum = 0;//真约数之和就是sum
      for (int i = 1; i < a; i++)//0不是任何一个数的真约数,那么就不理它啦;而a不是a的真约数,出于方便,终止循环的条件这里就是i=a了
      {
      if (a%i == 0)//i能整除a,那么i就是a的一个真约数;注意“==”不要写成“=”
      {
      sum += i;//加上这个真约数~
      }
      }
      if (sum == a)//判断是不是完数
      return true;//是,则返回真
      else
      return false;//否,则返回假
      }
      int main()
      {
      int m;
      int n = 0;//n是记录完数个数的
      cin >> m;
      for (int i = 1/*注意i的初始值*/; i <= m; i++)
      {
      if (judge(i))//判断i是不是完数
      n++;
      }
      cout << n << endl;
      return 0;
      }
      /*
      说在最后:
      1.题目虽然不会太难,但还是不要轻敌,考试的时候千万不要**非要用不熟悉的骚方法。
      2.由于题目都是非常短小简单的,尽量少用


      来自Android客户端3楼2017-06-15 23:12
      回复
        类,不要给自己增加打字的负担。
        3.如果对明天考试有点方的朋友,可以尝试带一张纸、带一支笔,看到题目以后,先把步骤分清楚,脑子里大概明白整个程序里面应该有什么东西以后,再敲键盘
        4。关于调试......这个是麻烦事,万一遇到BUG,心态稳住
        */
        私货~祝大家考试顺利哦
        #include<iostream>
        using namespace std;
        int main()
        {
        for (int i = 0; i < 6; i++)
        {
        for (int j = 0; j < 10-i; j++)
        cout << ' ';
        for (int j = 0; j < 5 + 2 * i; j++)
        cout << '*';
        for (int j = 0; j < 10 - i*2; j++)
        cout << ' ';
        for (int j = 0; j < 5 + 2 * i; j++)
        cout << '*';
        cout << endl;
        }
        for (int i = 0; i < 14; i++)
        {
        for (int j = 0; j < 6 + i; j++)
        cout << ' ';
        for (int j = 0; j < 28-i*2; j++)
        cout << '*';
        cout << endl;
        }
        cout << "---------------我是分割线---------------"<<endl;
        cout << "************祝大家考试顺利哦************" << endl;
        return 0;
        }


        来自Android客户端4楼2017-06-15 23:13
        回复


          IP属地:北京来自Android客户端5楼2017-06-15 23:36
          回复
            任意输入一个4位数整数年份,判断是否闰年。闰年规则:非整百年能被4整除为闰年,2004是,2100不是;整百年能被400整除为闰年,2000是,1900不是。
            输入
            2016
            输出

            样例输入
            2100
            样例输出
            不是
            提示
            #include<iostream>
            #include<cmath>
            using namespace std;
            int main()
            {
            int a;
            cin>>a;
            if ((a%4==0&&a%100!=0)||(a%400==0))
            cout<<"是"<<endl;
            else cout<<"不是"<<endl;
            return 0;
            }


            7楼2017-06-16 00:35
            回复
              欧几里德算法即使用辗转相除法求解两个自然数m和n的最大公约数,假定m>=n。
              输入
              25 15
              输出
              5
              样例输入
              32 8
              样例输出
              8
              提示
              #include<iostream>
              using namespace std;
              int main()
              {
              int a,b,m,n,t;
              cin>>a>>b;
              if (a>b)
              m=a,n=b;
              else m=b,n=a;
              do {t=m%n;
              m=n,n=t;
              }while(t!=0);
              cout<<m;
              return 0;
              }


              8楼2017-06-16 00:36
              回复
                定义一个时间类,数据成员包括年、月、日,它的函数成员分别可以设置时间、显示时间,其中显示时间的函数,使用重载函数定义,遇到整型数值,则返回2017-5-30的格式,遇到浮点型数值,则输出2017年5月30日的格式。
                输入:2017 5 30 1.1
                输出:2017年5月30日
                #include <iostream>
                using namespace std;
                class Time{
                private:int year; int month; int day;
                public:
                Time(int y, int m,int d)
                {
                year = y;
                month = m;
                day = d;
                }
                void showtime(int)
                {
                cout << year << "-" << month << "-" << day ;
                }
                void showtime(float)
                {
                cout << year << "年" << month << "月" << day << "日";
                }
                };
                int main()
                {
                int year, month, day;
                cin >> year >> month >> day;
                Time thisday(year,month,day);
                char a[100];
                cin >> a;
                int i=0, b=0;
                for (i = 0; a[i] != '\0'; i++)
                {
                if (a[i] == '.'){ b = 1; break; }
                }
                if (b == 0)thisday.showtime(1);
                else thisday.showtime(1.1f);
                return 0;
                }


                IP属地:上海9楼2017-06-16 00:49
                回复
                  设计雇员Employee类,包含雇员的情况,工号、姓名、工资等级(每月工资数,整型数值)、受雇时间(年、月、日)。编写程序测试Employee类。要求输入任意员工工号,及当前日期(年、月,此日期应晚于受雇时间),输出该员工姓名接应得到的工资总额,中间用空格隔开。
                  已知当前所有员工信息如下:
                  1,"wang",5000,2000,10,23
                  2,"liu",4500,2008,1,20
                  3,"huo",3800,2003,7,3
                  4,"ma",5300,2015,4,10
                  5,"meng",6000,2016,3,16
                  输入:5 2016 5
                  输出:meng 12000
                  #include <iostream>
                  #include<string>
                  using namespace std;
                  class employee{
                  private:int id; string name; int salary; int year; int month; int day;
                  public:employee(int i, string n, int s, int y, int m, int d)
                  {
                  id = i; name = n; salary = s; year = y; month = m; day = d;
                  }
                  void show(int y,int m)
                  {
                  cout << name<<" "<<(y-year)*12*salary+(m-month)*salary;
                  }
                  };
                  int main()
                  {
                  employee a[5] = {
                  employee(1, "wang", 5000, 2000, 10, 23),
                  employee(2, "liu", 4500, 2008, 1, 20),
                  employee(3, "huo", 3800, 2003, 7, 3),
                  employee(4, "ma", 5300, 2015, 4, 10),
                  employee(5, "meng", 6000, 2016, 3, 16) };
                  int n, y, m;
                  cin >> n >> y >> m;
                  a[n-1].show(y, m);
                  }


                  IP属地:上海10楼2017-06-16 00:51
                  回复
                    定义一个Cirle类,包括数据成员Radius(半径)和计算周长、面积的成员函数,并构造Cirle的对象进行测试。键盘输入半径,输出周长和面积值,中间用1个空格分隔,数据类型均为double,圆周率Pi=3.14。
                    输入:5
                    输出:周长31.4 面积78.5
                    #include <iostream>
                    using namespace std;
                    class Circle{
                    private:
                    float Radious;
                    public:
                    Circle(float r)
                    {
                    Radious = r;
                    }
                    void length();
                    void area();
                    };
                    void Circle::length()
                    {
                    cout <<"周长"<< 6.28*Radious<<" ";
                    }
                    void Circle::area()
                    {
                    cout <<"面积"<< 3.14*Radious*Radious;
                    }
                    int main()
                    {
                    float r;
                    cin >> r;
                    Circle A(r);
                    A.length();
                    A.area();
                    return 0;
                    }


                    IP属地:上海11楼2017-06-16 00:52
                    回复


                      来自Android客户端12楼2017-06-16 00:53
                      回复
                        定义一个矩形类,长和宽是它的属性,可以求出矩形的面积。定义一个比较函数,比较两个矩形的面积,把面积大的矩形对象作为引用来返回。主函数中定义两个矩形,它们的长、宽已知,分别为矩形1:长5.2、宽4.3,矩形2:长100、宽20。再由键盘输入一个矩形的长、宽。调用比较函数进行比较,找出面积大的矩形,输出其面积。
                        输入:10 8
                        输出:2000
                        #include <iostream>
                        using namespace std;
                        class rectangle
                        {
                        private:
                        float length;
                        float width;
                        public:
                        void setrectangle(float newL, float newW)
                        {
                        length = newL; width = newW;
                        }
                        float area()
                        {
                        return length*width;
                        }
                        };
                        int main()
                        {
                        rectangle A, B, C;
                        A.setrectangle(5.2, 4.3);
                        B.setrectangle(100, 20);
                        float newL, newW;
                        cin >>newL>>newW ;
                        C.setrectangle(newL, newW);
                        rectangle& compare(rectangle&, rectangle&);
                        rectangle&max = compare(C, compare(A, B));
                        cout << max.area();
                        return 0;
                        }
                        rectangle& compare(rectangle&A, rectangle&B)
                        {
                        if (A.area() > B.area())
                        return A;
                        else return B;
                        }


                        IP属地:上海13楼2017-06-16 00:53
                        回复
                          定义一个Triangle三角形类,包括数据成员三边边长(int类型)、判断三角形形状的成员函数。键盘输入三角形三边边长,判断此三角形形状(其中,等腰直角三角形归为等腰三角形类)。
                          构成等边三角形,输出“A equileteral triangle”;
                          构成等腰三角形,输出“A isosceles triangle”;
                          构成直角三角形,输出“A right triangle”;
                          构成三角形,但不是以上三种,则输出“A triangle”;
                          不构成,输出“Not a triangle”。
                          输入:3 4 5
                          输出:A right triangle
                          #include <iostream>
                          using namespace std;
                          class Triangle{
                          private :
                          float a, b, c;
                          public:
                          Triangle(float newA, float newB, float newC)
                          :a(newA), b(newB), c(newC){};
                          void judge();
                          };
                          void Triangle::judge()
                          {
                          if (a + b > c&&b + c > a&&a + c > b)
                          {
                          if (a == b&&a == c)
                          cout << "A equileteral triangle";
                          else if ((a == b&&a != c) || (b == c&&b != a) || (c == a&& c != b))
                          cout << "A isosceles triangle";
                          else if ((c*c == a*a + b*b) || (b*b == a*a + c*c) || (a*a == b*b + c*c))
                          cout << "A right triangle";
                          else cout << "A triangle";
                          }
                          else cout << "Not a triangle";
                          }
                          int main()
                          {
                          float a, b, c;
                          cin >> a >> b >> c;
                          Triangle t(a, b, c);
                          t.judge();
                          return 0;
                          }


                          IP属地:上海14楼2017-06-16 00:53
                          回复
                            题目描述
                            用字符指针数组,将给定的5个字符串(可以是任意5个国家名字)进行排序并输出。
                            输入
                            China American France Spain Greece
                            输出
                            American
                            China
                            France
                            Greece
                            Spain
                            #include<iostream>
                            #include<string>
                            using namespace std;
                            int main()
                            {
                            string t;
                            string a[5];
                            for (int i = 0; i < 5; ++i)
                            cin >> a[i];
                            for (int j = 0; j < 5;++j)
                            {
                            for (int i = 0; i < 4; ++i)
                            {
                            if (a[i]>a[i + 1])
                            {
                            t=a[i];
                            a[i] = a[i + 1];
                            a[i + 1] = t;
                            }
                            }
                            }
                            for (int i = 0; i < 5; ++i)
                            cout << a[i] << '\n';
                            return 0;
                            }


                            IP属地:上海15楼2017-06-16 00:54
                            回复
                              题目描述
                              已知有3名学生及五门课程的成绩,要求根据学生的各科平均分排序(降序),并输出学生的所有信息和平均分(用指针数组完成)。
                              输入
                              Jane 90 80 75 60 85
                              Mark 85 78 98 85 86
                              Lily 56 65 75 68 80
                              输出
                              Mark 85 78 98 85 86 86.4
                              Jane 90 80 75 60 85 78
                              Lily 56 65 75 68 80 68.8
                              #include<iostream>
                              using namespace std;
                              struct student{
                              char name[20];
                              int s[5];
                              float a;
                              }b[3];
                              int main()
                              {
                              // student *pa[3] = { &b[0], &b[1], &b[2] };
                              student temp;
                              for (int i = 0; i < 3; ++i)
                              {
                              int sum = 0;
                              cin >> b[i].name;
                              for (int j = 0; j < 5; ++j)
                              {
                              cin >> b[i].s[j];
                              sum += b[i].s[j];
                              }
                              b[i].a = sum / 5.0;
                              }
                              for (int i = 1; i <=3; ++i)
                              {
                              for (int j = 0; j <= 3 - i; ++j)
                              {
                              if (b[j].a < b[j + 1].a)
                              {
                              temp = b[j];
                              b[j] = b[j + 1];
                              b[j + 1] = temp;
                              }
                              }
                              }
                              for (int i = 0; i < 3; ++i)
                              {
                              cout << b[i].name << " ";
                              for (int j = 0; j < 5; j++)
                              cout << b[i].s[j] << " ";
                              cout<< b[i].a<<'\n';
                              }
                              }


                              IP属地:上海16楼2017-06-16 00:56
                              回复