62,046
社区成员
发帖
与我相关
我的任务
分享
for (int i = 10; i > 0; i--)
{
for (int j = 1; j < i; j++)
{
Response.Write(i.ToString() + "-" + j.ToString() + "=" + (i - j).ToString()+"<br>");
}
}
public class Answer
{
private static string[] expression_add = { "+", "加"};
private static string[] expression_minus = { "-", "减" };
private static string[] result = { "=", "等于" };
private static string[] str_num = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
static void Main(string[] args)
{
int answer = 0;
string question = string.Empty;
int num = 0;
//循环第一个数
for(int i = 0;i < str_num.Length;i++)
{
//循环第二个数
for(int j = 0;j < str_num.Length;j++)
{
//循环等号
for(int k = 0;k < result.Length;k++)
{
//计算加法结果
answer = (i % 10) + 1 + (j % 10) + 1;
//循环加法符号
for(int m = 0;m < expression_add.Length;m++)
{
question = str_num[i] + expression_add[m] + str_num[j] + result[k] + "?";
Insert(question, answer);
}
//计算减法结果
answer = (i % 10) + 1 - (j % 10) - 1;
//去掉减法结果小于0的表达式
if(answer <= 0)
{
break;
}
for(int n = 0;n < expression_minus.Length;n++)
{
question = str_num[i] + expression_minus[n] + str_num[j] + result[k] + "?";
Insert(question, answer);
}
}
}
}
Console.WriteLine("total:" + num);
Console.ReadKey();
}
static void Insert(string question, int answer)
{
Question.InsertQuestionAnswer(question, answer.ToString());
}
}