-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathProgram.cs
More file actions
80 lines (76 loc) · 2.21 KB
/
Program.cs
File metadata and controls
80 lines (76 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace ConsoleApplication1
{
public class Program
{
public void GreatCalculation(int n)
{
bool test = false;
Random r = new Random();
int op = r.Next(2, 4);//符号数
List<int> l = new List<int>();
List<int> f = new List<int>();
for (int li = 0; li < n; )
{
for (int i = 0; i < op; i++)
{
f.Add(r.Next(1, 5));
}
for (int i = 0; i <= op; i++)
{
l.Add(r.Next(0, 100));
}
Dictionary<int, string> h = new Dictionary<int, string> { { 1, "+" }, { 2, "-" }, { 3, "*" }, { 4, "/" } };
for (int i = 0; i < f.Count(); i++)
{
if (h[f[i]] == "/" && l[i] == 0)
test = false;
else
test = true;
}
string str = "";
for (int i = 0; i < f.Count; )
{
if (i == 0)
{
str = l[i].ToString() + h[f[i]].ToString() + l[i + 1].ToString();
i += 1;
}
else
{
str += h[f[i]].ToString() + l[i + 1].ToString();
i += 1;
}
}
if (test)
{
test = false;
DataTable table = new DataTable();
var re = table.Compute(str, null);
int s;
if (int.TryParse(re.ToString(), out s))
{
Console.WriteLine(str + "=" + re.ToString());
test = true;
}
}
if (test == true)
li++;
l.Clear();
f.Clear();
}
}
static void Main(string[] args)
{
Console.Write("请输入题目个数:");
int n = Convert.ToInt32(Console.ReadLine());
Program c = new Program();
c.GreatCalculation(n);
}
}
}