大佬给我看看
整钱换零钱,一元钱可兑换成1角,2角,5角,问共有多少种方案,并请按格式输出所有的方案。第一行开始,按格式输出所有的方案
最后一行输出多少种方案
程序代码:#include <stdio.h>
typedef struct dollar_sys {
int dime;
int tw_cents;
int hf_dollar;
}vdos;
int calc_dos(vdos *pdos)
{
int one_dollar = 100;
one_dollar -= pdos->dime * 10;
if (one_dollar < 0) return 0;
one_dollar -= pdos->tw_cents * 20;
if (one_dollar < 0) return 0;
one_dollar -= pdos->hf_dollar * 50;
if (one_dollar < 0) return 0;
return 0 == one_dollar ? 1 : 0;
}
int main(int argc, char *argv[])
{
vdos dos = {0};
int i = 0;
#define USR_EXP_CNT 1000
while (i++ < USR_EXP_CNT) {
dos.dime = ((unsigned char *)main)[i] % 10;
dos.tw_cents = ((unsigned char *)calc_dos)[i + 1] % 10;
dos.hf_dollar = ((unsigned char *)main)[i + 2] % 10;
if (calc_dos(&dos)) {
puts("Mr.main bingo!");
printf("dime = %d ", dos.dime);
printf("tw_cents = %d ", dos.tw_cents);
printf("hf_dollar = %d\n", dos.hf_dollar);
puts("------------------------------------");
}
}
return 0;
}
程序代码:#include <stdio.h>
typedef struct mini_game_obj {
int level;
int exp;
int achv[11];
}vmg;
typedef struct dollar_obj {
int dime;
int tw_cents;
int hf_dollar;
vmg mg;
}vdos;
int calc_dos(vdos *pdos)
{
int one_dollar = 100;
one_dollar -= pdos->dime * 10;
if (one_dollar < 0) return 0;
one_dollar -= pdos->tw_cents * 20;
if (one_dollar < 0) return 0;
one_dollar -= pdos->hf_dollar * 50;
if (one_dollar < 0) return 0;
return 0 == one_dollar ? 1 : 0;
}
int check_sum(int *cs, int rs)
{
int i;
for (i = 0; i < 10; i++)
if (cs[i] == rs) return 1;
return 0;
}
int main(int argc, char *argv[])
{
vdos dos = {0};
int i = 0;
#define USR_EXP_CNT 1000
while (i++ < USR_EXP_CNT) {
dos.dime = ((unsigned char *)main)[i] % 10;
dos.tw_cents = ((unsigned char *)calc_dos)[i + 1] % 10;
dos.hf_dollar = ((unsigned char *)main)[i + 2] % 10;
if (calc_dos(&dos)) {
#define REC_PTR 10
#define rec_sum (dos.dime * 100 + dos.tw_cents * 10 + dos.hf_dollar)
//new rec_sum
if (!check_sum(dos.mg.achv, rec_sum)) {
dos.mg.achv[dos.mg.achv[REC_PTR]++] = rec_sum;
puts("!!---new achievement---!!");
#define add_exp (dos.dime + dos.tw_cents + dos.hf_dollar)
dos.mg.exp += add_exp;
printf("obtained exp: %d\n", add_exp);
} else {
// exp /= 2;
dos.mg.exp += (add_exp >> 1);
printf("obtained exp: %d\n", (add_exp >> 1));
}
//show status
printf("Mr.main[LV_%d] bingo! exp = %d\n",
dos.mg.level, dos.mg.exp);
printf("dime = %d ", dos.dime);
printf("tw_cents = %d ", dos.tw_cents);
printf("hf_dollar = %d\n", dos.hf_dollar);
//level up
#define FIXED_LEVEL_UP 25
if (dos.mg.exp >= FIXED_LEVEL_UP) {
puts("Mr.main LV up!!!");
dos.mg.level++; dos.mg.exp -= 25;
}
puts("------------------------------------");
}
}
return 0;
}