Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using System;
- using System.Threading;
- namespace serialize
- {
- static class Constants
- {
- public const int mod1 = 101;// +-
- public const int mod2 = 101;// +-
- public const int mod3 = 11;// */
- public const int mod4 = 11;// */
- }
- class Program
- {
- public static char GetSign()
- {
- Random rnd = new Random();
- int tmp = rnd.Next() % 4;
- char result = '.';
- switch (tmp)
- {
- case (0):
- result = '+';
- break;
- case (1):
- result = '-';
- break;
- case (2):
- result = '*';
- break;
- case (3):
- result = '/';
- break;
- default:
- break;
- }
- return result;
- }
- public (int, int) GetPair(int mod1 = Constants.mod1, int mod2 = Constants.mod2)
- {
- Random rnd = new Random();
- int res1, res2;
- res1 = (rnd.Next() % mod1) + 1;
- res2 = (rnd.Next() % mod2) + 1;
- return (res1, res2);
- }
- public (string, char, string, int) Build(char Sign)
- // first sign second result
- {
- (string, char, string, int) result;
- if (Sign == '+')
- {
- (int, int) Expression = GetPair();
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 + Expression.Item2;
- }
- else
- if (Sign == '-')
- {
- (int, int) Expression = GetPair();
- if (Expression.Item1 < Expression.Item2)
- {
- int a = Expression.Item1;
- Expression.Item1 = Expression.Item2;
- Expression.Item2 = a;
- }
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 - Expression.Item2;
- }
- else
- if (Sign == '/')
- {
- (int, int) Expression = GetPair(Constants.mod3, Constants.mod4);
- Expression.Item1 = Expression.Item2 * Expression.Item1;
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 / Expression.Item2;
- }
- else
- {
- (int, int) Expression = GetPair(Constants.mod3, Constants.mod4);
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 * Expression.Item2;
- }
- return result;
- }
- static void Main(string[] args)
- {
- for (int i = 0; i < 25; ++i)
- {
- Program abs = new Program();
- Thread.Sleep(1);
- //for (int j = 0; j < 6500000; j++) ;
- var a = abs.Build(GetSign());
- Console.WriteLine(a);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment