0 of 9 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 9 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
1、阅读程序写结果: (2008年真题)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include<iostream> using namespace std; void foo(int a, int b, int c){ if(a > b) foo(c, a, b); else cout<<a<<','<<b<<','<<c<<endl; } int main(){ int a, b, c; cin >> a >> b >> c; foo(a, b, c); return 0; } |
输入:3 1 2 输出为:
2、阅读程序写结果 (2008年真题)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<iostream> using namespace std; void f(int a, int b, int c) { cout << a << b << c << ‘/’; if(a == 3 && b == 2 && c == 1) return; if(b < c) f(a, c, b); else if(a < b) { if(a < c) f(c, a, b); else f(b, c, a); } } int main() { int a, b, c; cin >> a >> b >> c; f(a, b, c); cout << endl; return 0; } |
输入:1 3 2
输出:
3、阅读程序写结果 。
1 2 3 4 5 6 7 8 9 10 11 12 |
#include<iostream> using namespace std; int fib(int n){ if (n <= 1) return n; return fib(n-1) + fib(n-2); } int main (){ int n ; cin>>n; cout << fib(n); return 0; } |
当n输入为5时,输出为多少?
4、阅读程序写结果: (2014年普及组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <iostream> using namespace std; int fun(int n){ if(n == 1) return 1; if(n == 2) return 2; return fun(n -2) - fun(n - 1); } int main(){ int n; cin >> n; cout << fun(n) << endl; return 0; } |
输入:7 输出:
5、阅读程序写结果:(2009年真题)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <iostream> using namespace std; int a,b; int work(int a,int b){ if (a%b) return work(b,a%b); return b; } int main(){ cin >> a >> b; cout << work(a,b) << endl; return 0; } |
输入:20 12 输出:
6、阅读程序写结果: (2010年真题)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <iostream> using namespace std; const int NUM = 5; int r(int n){ int i; if (n <= NUM) return n; for (i = 1; i <= NUM; i++) if (r(n - i) < 0) return i; return -1; } int main(){ int n; cin>>n; cout<<r(n)<<endl; return 0; } |
输入7,输出结果为
输入16,输出结果为
7、阅读程序写结果 (2011年普及组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include<iostream> using namespace std; int solve(int n,int m) { int i,sum; if(m==1) return 1; sum=0; for(i=1;i<n;i++) sum+= solve(i,m-1); return sum; } int main() { int n,m; cin>>n>>m; cout<<solve(n,m)<<endl; return 0; } |
输入:7 4 输出:
8、阅读下面程序,写出输出结果。(2012年普及组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> using namespace std; int n,i,j,a[100][100]; int solve(int x,int y) { int u,v; if(x==n) return a[x][y]; u=solve(x+1,y); v=solve(x+1,y+1); if(u>v) return a[x][y]+u; else return a[x][y]+v; } int main() { cin>>n; for(i=1;i<=n;i++) for(j=1;j<=i;j++) cin>>a[i][j]; cout<<solve(1,1)<<endl; return 0; } |
输入:
5
2
-1 4
2 -1 -2
-1 6 4 0
3 2 -1 5 8
输出结果:
9、阅读程序,根据输入写出结果: (2014年提高组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <stdio.h> int fun( int n, int minNum, int maxNum ) { int tot, i; if ( n == 0 ) return(1); tot = 0; for ( i = minNum; i <= maxNum; i++ ) tot += fun( n - 1, i + 1, maxNum ); return(tot); } int main() { int n, m; scanf( "%d%d ", &n, &m ); printf( "%d\n", fun( m, 1, n ) ); return(0); } |
输入:6 3 输出: