You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in page 14, code of using flag as follows. the ans = 5913.
bool flag = true;
int ans = 0;
for (int i = 1; i <= 10 && flag; ++i)
{
int t = 1;
for (int j = 1; j <= i && flag ; ++j)
{
t *= j;
if (t > 1000) flag = false;
}
ans += t;
}
in page 14, code of using goto as follows. the ans = 873.
int ans = 0;
for (int i = 1; i <= 10; ++i)
{
int t = 1;
for (int j = 1; j <= i; ++j)
{
t *= j;
if (t > 1000) goto loop;
}
ans += t;
}
loop:;
this is because ans += t; excute more once in first code.
so we can move if statement to behiend the ans += t;
the new code as follwos, the ans = 5913.
int ans = 0;
for (int i = 1; i <= 10; ++i)
{
int t = 1;
for (int j = 1; j <= i; ++j)
{
t *= j;
}
ans += t;
if (t > 1000) goto loop;
}
loop:;
in page 14, code of using flag as follows. the ans = 5913.
bool flag = true;
int ans = 0;
for (int i = 1; i <= 10 && flag; ++i)
{
int t = 1;
for (int j = 1; j <= i && flag ; ++j)
{
t *= j;
if (t > 1000) flag = false;
}
ans += t;
}
in page 14, code of using goto as follows. the ans = 873.
int ans = 0;
for (int i = 1; i <= 10; ++i)
{
int t = 1;
for (int j = 1; j <= i; ++j)
{
t *= j;
if (t > 1000) goto loop;
}
ans += t;
}
loop:;
this is because ans += t; excute more once in first code.
so we can move if statement to behiend the ans += t;
the new code as follwos, the ans = 5913.
int ans = 0;
for (int i = 1; i <= 10; ++i)
{
int t = 1;
for (int j = 1; j <= i; ++j)
{
t *= j;
}
ans += t;
if (t > 1000) goto loop;
}
loop:;
chncys
email: [email protected]
qq: [email protected]
WeChat ID: cys7749
The text was updated successfully, but these errors were encountered: