#include
void main()
{
int time=1,count=0;
for(;time<141;time++)
if((time%5==0&&time%6==0)||(time%7==0&&time%5==0)||(time%7==0&&time%6==0))
//原来的答案是按照105秒来计算的,错误!
count++;
count+=2; //一开始应该是time=0减去两个,所以应该cout加上2
printf("所应该减去的次数%d\n",count);
count=63-count;
printf("可以听到的次数=%d",count);
//结果为五十,已经通过数学方法验证,不是五十四次!
}
1, 可以利用基数排序的思想。
#include
int main(void)
{
int a[141] = {0};
int i, sum = 0;
for (i = 0; i < 21; i++) {
a[i * 5] = 1;
a[i * 6] = 1;
a[i * 7] = 1;
}
for (i = 0; i < 141; i++) {
if (a[i] == 1)
sum++;
}
printf("%d times\n", sum);
return 0;
}
2,
#include
int main(void)
{
int a[5][5];
int i, j;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
if (i == j || 4 - i == j || 4 - j == i)
a[i][j] = '*';
else
a[i][j] = '#';
printf("%c", a[i][j]);
}
printf("\n");
}
return 0;
}
//第一题答案
#include
void main()
{
int time = 0, Ta = 0, Tb = 0, Tc = 0, Tt = 0;
int b_b = 0; //0 not 1 have ;
for(;Ta < 21 || Tb < 21 || Tc <21; time++)
{
if(Ta < 21 && time % 5 == 0)
{Ta++; b_b = 1; Tt++ ;}
if(Tb < 21 && time % 6 == 0)//B
{
Tb++;
if(b_b == 0)
{ Tt++; b_b = 1;}
}
if(Tc<21&&time%7==0)
{
Tc++;
if(b_b == 0)
{ Tt++;
b_b = 1;
}
}
b_b=0;
}
printf("%d\n",Tt);
}
==============================================================