0 noip阅读程序题 打印版
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
全国信息学奥林匹克竞赛阅读程序题
1、#include
using namespace std;
int main()
{
freopen("d1.in","r",stdin);
freopen("d1.out","w",stdout);
int a, b, c;
a = 1;
b = 2;
c = 3;
if (a > b && a > c)
cout << a << ' ';
else
{
if(b>c)
cout << b << ' ';
else
cout< } } 程序运行结果: 3□ 2、#include using namespace std; int main() { freopen("a.in","r",stdin); freopen("a.out","w",stdout); int p,q,s,t; cin>>p; for(q=p+1;q<=p*2;++q) { t=0; s=(p*q)%(q-p); if(s==0) { t=p+q+(p*q)/(q-p); cout< } } } 输入:12 根据程序列表分别计算各变量的值: □181□110□□87□□76□□66□□62□□61□□60 3、#include using namespace std; int main() { freopen("d1.in","r",stdin); freopen("d1.out","w",stdout); int max, min, sum, count=0; int tmp; cin >> tmp; if (tmp == 0) return 0; max = min = sum = tmp; count++; while(tmp != 0) { cin >> tmp; if (tmp != 0) { sum += tmp; count++; if (tmp > max) max = tmp; if (tmp < min) min = tmp; } } cout << max <<"," << min << "," << sum / count<< endl; return 0; } d1.in 1 2 3 4 5 6 0 7 tmp=1 max=2 min=1 sum=3 count=2 tmp=2 max=3 min=1 sum=6 count=3 tmp=3 max=4 min=1 sum=10 count=4 tmp=4 max=5 min=1 sum=15 count=5 tmp=5 max=6 min=1 sum=21 count=6 tmp=6 {当循环至读入6后,条件tmp<>0为trun, 循环结束,输出结果} 程序运行结果: 6,1,3 4、#include using namespace std; long int a,b,n; int main() { freopen("c3.in","r",stdin); freopen("c3.out","w",stdout); cin>>n; a=0;b=0; do { a=a+1; b=b+a; } while (!(b>=n));