zoukankan      html  css  js  c++  java
  • 作业12.24

    1.有三种硬币若干:1分,2分,5分。要组合1毛5,有哪些组合方式?

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ConsoleApplication4
     7 {
     8     class 硬币
     9     {
    10         //硬币有若干:1分的,2分的,5分的。要组合1毛5,有哪些组合方式?
    11         static void Main(string[] args)
    12         {
    13             for (int a = 0; a <= 15; a++)
    14             {
    15                 for (int b = 0; b <= 7; b++)
    16                 {
    17                     for (int c = 0; b <= 3; c++)
    18                     {
    19                         if (a*1+b*2+c*3==15)
    20                         {
    21                             Console.WriteLine();
    22                         }
    23                     }
    24                 }
    25             }
    26         }
    27     }
    28 }

    2.买东西。小张过元旦发了100元的购物券,他要买香皂(5元),牙刷(2元),洗发水(20元)。要想把100元正好花完,如何买这三样东西?

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ConsoleApplication4
     7 {
     8     class 元旦
     9     {
    10         //购物券100元,香皂(5元),牙刷(2元),洗发水(20元)。正好花完,怎么花?
    11         static void Main(string[] args)
    12         {
    13             for (int a=0;a<=20;a++)
    14             {
    15                 for (int b = 0; b <= 50; b++)
    16                 {
    17                     for (int c = 0; c <= 5;c++ )
    18                     {
    19                         if (5*a+2*b+20*c==100)
    20                         {
    21                             Console.WriteLine("应该买香皂"+a+"块,牙刷"+b+"只,洗发水"+c+"瓶。");
    22                         }
    23                     }
    24                 }
    25             }
    26         }
    27     }
    28 }

    3.百鸡百钱。有100文钱,要买100只鸡回家。公鸡2文钱一只,母鸡1文钱一只,小鸡半文钱一只。如何买?

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ConsoleApplication4
     7 {
     8     class 百钱白鸡
     9     {
    10         //有100文钱,要买100只鸡回家。公鸡2文钱一只,母鸡一文钱一只,小鸡半文钱一只。如何买?
    11         static void Main(string[] args)
    12         {
    13             for (int a = 0; a <= 50;a++ )
    14             {
    15                 for (int b = 0; b <= 100;b++ )
    16                 {
    17                     for (double c = 0; c <= 200;c++ )
    18                     {
    19                         if(a*2+b*1+c*0.5==100&&a+b+c==100)
    20                         {
    21                             Console.WriteLine("公鸡"+a+"只,母鸡"+b+"只,小鸡"+c+"只。");
    22                         }
    23                     }
    24                 }
    25             }
    26         }
    27     }
    28 }

    4.某侦察队接到一项紧急任务,要求在A、B、C、D、E、F六个队员中尽可能多地挑若干人,但有以下限制条件:
    A和B两人中至少去一人;                                   a+b>=1
    A和D不能一起去;                                           a+d<=1
    A、E和F三人中要派两人去;                              a+e+f==2
    B和C都去或都不去;                                        b+c!=1
    C和D两人中去一个;                                        c+d==1
    若D不去,则E也不去。                                      d+e==0||d==1
    问应当让哪几个人去?

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ConsoleApplication4
     7 {
     8     class 侦察队
     9     {
    10         static void Main(string[] args)
    11         {
    12             for (int a = 0; a <= 1;a++ )
    13             {
    14                 for (int b = 0; b <= 1;b++ )
    15                 {
    16                     for (int c = 0; c <= 1;c++ )
    17                     {
    18                         for (int d = 0; d <= 1;d++ )
    19                         {
    20                             for (int e = 0; e <= 1;e++ )
    21                             {
    22                                 for (int f = 0; f <= 1;f++ )
    23                                 {
    24                                     if (a + b >= 1 && a + d <= 1 && a + e + f == 2 && b + c != 1 && c + d == 1 && (d + e == 0 || d == 1))
    25                                     {
    26                                         Console.WriteLine("a="+a+";b="+b+";c="+c+";d="+d+";e="+e+";f="+f);
    27                                     }
    28                                 }
    29                             }
    30                         }
    31                     }
    32                 }
    33 
    34             }
    35         }
    36     }
    37 }

    5.123()45()67()8()9=100;要求在()里面填写+或-使等式成立。

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ConsoleApplication4
     7 {
     8     class Class1
     9     {
    10         //123()45()67()8()9=100;要求在()里面填写+或-使等式成立。
    11         static void fff(string[] args)
    12         {
    13             for (int a = -1; a <= 1;a=a+2 )//-1代表减号,1代表加号
    14             {
    15                 for (int b = -1; b <= 1;b=b+2 )
    16                 {
    17                     for (int c = -1; c <= 1;c=c+2 )
    18                     {
    19                         for (int d = -1; d <= 1;d=d+2 )
    20                         {
    21                             if (123+a*45+67*b+8*c+9*d==100)
    22                             {
    23                                 Console.WriteLine("a="+a+";b="+b+";c="+c+";d="+d);
    24                             }
    25                         }
    26                     }
    27                 }
    28             }
    29         }
    30     }
    31 }
  • 相关阅读:
    android监控来电显示
    android 选择本地图片并预览
    解决android http请求带中文参数会乱码(url编码)
    android连接webservice是cookies和session保持方法
    eclipse中android自动补全/提示卡机或假死
    JS中创建类得几种方式
    AJAX的简单实例应用
    JavaScript中的eval函数的用法
    JSON 入门指南
    JS中关于clientWidth、offsetWidth、scrollWidth
  • 原文地址:https://www.cnblogs.com/viven/p/4182658.html
Copyright © 2011-2022 走看看