Visual Studio-图形用户界面设计-9.14第二讲

  • Post author:
  • Post category:其他




Problem A:判断成绩是否及格

题目描述

输入成绩的分数值s,如果s≥60,则为及格,输出pass;否则为不及格,输出fail



样例输入

60



样例输出

pass



答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            float s = float.Parse(Console.ReadLine());
            if (s >= 60)
            {
                Console.WriteLine("pass");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("fail");
                Console.ReadLine();
            }
            
        }
    }
}

在这里插入图片描述



Problem B:奇数与偶数

题目描述

输入整数n,如果n为奇数,输出odd;否则输出even



样例输入

1



样例输出

odd



答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());
            if (s % 2 == 0)
            {
                Console.WriteLine("even");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("odd");
                Console.ReadLine();
            }
            
        }
    }
}

在这里插入图片描述



Problem C:闰年与平年

题目描述

输入年份y,判断这个年份是否为闰年(闰年的条件是:年份能被4整除且不能被100整除,或能被400整除)



样例输入

【测试样例1】

2000

【测试样例2】

2012

【测试样例3】

2015

【测试样例4】

1900



样例输出

【测试样例1】

leap year

【测试样例2】

leap year

【测试样例3】

non-leap year

【测试样例4】

non-leap year



答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());
            if (s % 4 == 0 && s % 100 != 0 || s % 400 == 0)
            {
                Console.WriteLine("leap year");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("non-leap year");
                Console.ReadLine();
            }
            
        }
    }
}

在这里插入图片描述



Problem D:成绩的等级

题目描述

在这里插入图片描述



输入

输入一个百分制的成绩S,S为自然数并且0≤S≤100



输出

输出对应的等级(A、B、C、D、E)



样例输入

80



样例输出

B



答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());
            switch(s / 10)
            {
                case 10:
                    {
                        Console.WriteLine("A");
                        Console.ReadLine();
                        break;
                    }
                case 9:
                    {
                        Console.WriteLine("A");
                        Console.ReadLine();
                        break;
                    }
                case 8:
                    {
                        Console.WriteLine("B");
                        Console.ReadLine();
                        break;
                    }
                case 7:
                    {
                        Console.WriteLine("C");
                        Console.ReadLine();
                        break;
                    }
                case 6:
                    {
                        Console.WriteLine("D");
                        Console.ReadLine();
                        break;
                    }
                default:
                    {
                        Console.WriteLine("E");
                        Console.ReadLine();
                        break;
                    }
            }
        }
    }
}

在这里插入图片描述



Problem E:足球比赛计分

题目描述

在足球比赛中,每场比赛的计分规则与双方的进球数有关: 进球数多的一方获胜,计3分;进球数少的一方失败,计0分; 如果双方进球数相同(或双方都未进球),为平局,双方各计1分。

输入比赛双方的进球数,输出双方的得分。



输入

输入比赛双方的进球数。



输出

输出双方的得分,用1个空格分隔。



样例输入

0 0

6 1

0 1



样例输出

1 1

3 0

0 3



答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] sArray = s.Split(' ');
            if(int.Parse(sArray[0]) > int.Parse(sArray[1]))
            {
                Console.WriteLine("3 0");
                Console.ReadLine();
            }
            else if (int.Parse(sArray[0]) < int.Parse(sArray[1]))
            {
                Console.WriteLine("0 3");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("1 1");
                Console.ReadLine();
            }
        }
    }
}

在这里插入图片描述



Problem F:【分支结构】求解一元二次方程

题目描述

在这里插入图片描述



输入

输入a,b,c的值



输出

输出方程的解,如果有实数解,按照从大到小输出,保留一位小数。



样例输入

1 4 3



样例输出

x1=-1.0

x2=-3.0



答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] sArray = s.Split(' ');
            double a = double.Parse(sArray[0]);
            double b = double.Parse(sArray[1]);
            double c = double.Parse(sArray[2]);
            double d = b * b - 4 * a * c;
            if (d >= 0)
            {
                double x1 = (-b - Math.Sqrt(d)) / (2 * a);
                double x2 = (-b + Math.Sqrt(d)) / (2 * a);
                if (x1 >= x2)
                {
                    Console.WriteLine("x1={0:.0}",x1);
                    Console.WriteLine("x2={0:.0}",x2);
                    Console.ReadLine();
                }
                else if(x1 == x2)
                {
                    Console.WriteLine("x1={0:.0}", x1);
                    Console.WriteLine("x2={0:.0}", x1);
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("x1={0:.0}",x2);
                    Console.WriteLine("x2={0:.0}",x1);
                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine("no real solution");
                Console.ReadLine();
            }
        }
    }
}

在这里插入图片描述



Problem G:【入门】根据边长计算三角形的面积

题目描述

在这里插入图片描述



输入

输入三边a、b、c,三条边均为整数



输出

输出面积,保留6位小数



样例输入

3 4 5



样例输出

6.000000



答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] sArray = s.Split(' ');
            double a = double.Parse(sArray[0]);
            double b = double.Parse(sArray[1]);
            double c = double.Parse(sArray[2]);
            double d = (a + b + c) / 2;
            double area = Math.Sqrt(d * (d - a) * (d - b) * (d - c));

            Console.WriteLine("{0:.000000}", area);
            Console.ReadLine();
        }
    }
}

在这里插入图片描述



Problem H:【分支结构】三个整数a,b,c从小到大排序

题目描述

输入三个整数a,b,c;按照从小到大次序输出。



样例输入

1 2 3

3 2 1

6 6 6

100 10 1



样例输出

1 2 3

1 2 3

6 6 6

1 10 100



答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] sArray = s.Split(' ');
            int a = int.Parse(sArray[0]);
            int b = int.Parse(sArray[1]);
            int c = int.Parse(sArray[2]);
            int temp;
            if(a > b)
            {
                temp = a;
                a = b;
                b = temp;
            }
            if(a > c)
            {
                temp = a;
                a = c;
                c = temp;
            }
            if(b > c)
            {
                temp = b;
                b = c;
                c = temp;
            }

            Console.WriteLine("{0} {1} {2}",a,b,c);
            Console.ReadLine();
        }
    }
}

在这里插入图片描述



Problem I:判断三角形的类别

题目描述

在这里插入图片描述



输入

三个边长a、b、c,均为正整数



输出

如果以a、b、c为边长可以构成三角形,输出三角形的类别(英文缩写)

否则输出Not a triangle



样例输入

3 3 3

3 4 3

3 4 5

3 4 6

7 3 4

100 1 2



样例输出

ET

IT

RT

OT

Not a triangle

Not a triangle



答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] sArray = s.Split(' ');
            double a = double.Parse(sArray[0]);
            double b = double.Parse(sArray[1]);
            double c = double.Parse(sArray[2]);
            if (a + b > c && a + c > b && b + c > a)
            {
                if (a == b && a == c)
                {
                    Console.WriteLine("ET");
                    Console.ReadLine();
                }
                else if (a == b || a == c || b == c)
                {
                    Console.WriteLine("IT");
                    Console.ReadLine();
                }
                else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a)
                {
                    Console.WriteLine("RT");
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("OT");
                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine("Not a triangle");
                Console.ReadLine();
            }
        }
    }
}

在这里插入图片描述



版权声明:本文为Lulutia原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。