zoukankan      html  css  js  c++  java
  • 混合运算(控制台)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static int sun;
            private static int x, y, z;
            private static string  f;
            private static string  h;
            static void Main(string[] args)
            {
                Console.Write("请输入随机数的范围(9-10):");
                string azzz = Console.ReadLine();
                string regex = @"(d+)D+(d+)";
                Match mstr = Regex.Match(azzz, regex);
                int s1 = int.Parse(mstr.Groups[1].Value);
                int s2 = int.Parse(mstr.Groups[2].Value);
                random(s1,s2);
                Console.Write("请输入答案:");
                int l = int.Parse(Console.ReadLine());
                rightanswer(f, h, x, y, z);
                if (l == sun)
                {
                    Console.WriteLine("回答正确!");
                }
                else
                {
                    Console.WriteLine("回答错误!");
                }
                Console.Read();
            }
            private static void random(int a,int b)
            {
                Random si = new Random();
                x = si.Next(a, b);
                y = si.Next(a, x);
                z = si.Next(a, y);
                string[] operators = new string[] { "+", "-", "*", "/" };
                 f = operators[new Random().Next(0, 4)];
                 h = operators[new Random().Next(0, 4)];
                string z1 = "=";
                string xfyhz = x + f + y + h + z + z1;
                Console.WriteLine(xfyhz);
    
            }
            private static int rightanswer(string a1, string a2, int c, int d, int e)
            {
                string a12 = a1 + a2;
                switch (a12)
                {
                    case "++":
                        sun = c + d + e;
                        break;
                    case "+-":
                        sun = c + d - e;
                        break;
                    case "-+":
                        sun = c - d + e;
                        break;
                    case "--":
                        sun = c - d - e;
                        break;
                    case "-*":
                        sun = c - d * e;
                        break;
                    case "+*":
                        sun = c + d + e;
                        break;
                    case "*/":
                        sun = c * d / e;
                        break;
                    case "**":
                        sun = c * d * e;
                        break;
                    case "*-":
                        sun = c + d - e;
                        break;
                    case "*+":
                        sun = c * d + e;
                        break;
                    case "/*":
                        sun = c / d * e;
                        break;
                    case "/-":
                        sun = c / d - e;
                        break;
                    case "/+":
                        sun = c / d + e;
                        break;
                    case "//":
                        sun = c / d / e;
                        break;
                    case "-/":
                        sun = c - d / e;
                        break;
                    case "+/":
                        sun = c + d / e;
                        break;
                }
    
                return sun;
    
            }
        }
    }
    

    总结:
    改了很长时间,真是一点细微的细节都能决定程序的运行是否成功!写代码应该仔细,仔细,再仔细!

  • 相关阅读:
    vue中动态数据使用wowjs显示动画
    vue 切换路由页面不在最顶部
    dp,.单词的划分
    二分建火车站
    .最大上升子序列和
    饥饿的奶牛(不重区间最大值)
    F. 1.小W 的质数(prime)(欧拉筛)
    月月给华华出题
    积性函数
    垒石头(排序+dp)
  • 原文地址:https://www.cnblogs.com/lizanqirxx/p/4964507.html
Copyright © 2011-2022 走看看