第1个回答 2010-05-27
#include <stdio.h>
#include <conio.h>
int main()
{
int a,b,c,n=1;
for(a=0;a<=10;a++)
for(b=0;b<=5;b++)
for(c=0;c<=2;c++)
{
if(a*1+b*2+c*5==10)
printf("%d %d一分%d二分%d五分\n",n++,a,b,c);
}
getch();
return 0;
}
第2个回答 2018-06-15
private void Calculate()
{
int a, b, c;
int t = 0;
for (a = 0; a <= 20; a++)
{
for (b = 0; b <= (100 - 5 * a) / 2; b++)
{
c = 100 - 5 * a - 2 * b;
if (IsInt(c.ToString()))
{
if ((a * 5 + b * 2 + c * 1) == 100 && a >= 1 && b >= 1 & c >= 1)
{
if (a == 5 && b == 37 && c == 1)
{
int x = 0;
}
Console.WriteLine(": " + a.ToString() + " : " + b.ToString() + " : " + c.ToString());
t++;
}
}
}
}
Console.WriteLine("共计 " + t.ToString() + " 种方法");
}
public bool IsInt(string str)
{
bool bResult = false;
bResult = Regex.IsMatch(str, "^[0-9]+$");
return bResult;
}