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、阅读程序写结果: (2007年普及组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include "math.h" #include "stdio.h" int main() { int a1[51] = { 0 }; int i, j, t, t2, n = 50; for ( i = 2; i <= sqrt( n ); i++ ) if ( a1[i] == 0 ) { t2 = n / i; for ( j = 2; j <= t2; j++ ) a1[i * j] = 1; } t = 0; for ( i = 2; i <= n; i++ ) if ( a1[i] == 0 ) { printf( "%4d", i ); t++; if ( t % 10 == 0 ) printf( "\n" ); } printf( "\n" ); } |
程序输出为:(数字之间一个空格即可)
第一行 ;
第二行 ;
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 27 28 29 30 |
#include <iostream> using namespace std; void func(int ary[], int n ){ int i=0, j, x; j=n-1; while(i<j){ while (i<j&&ary[i]>0) i++; while (i<j&&ary[j]<0) j--; if (i<j){ x=ary[i]; ary[i++]=ary[j]; ary[j--]=x; } } } int main(){ int a[20], i, m; m=10; for(i=0; i<m; i++){ cin>>a[i]; } func(a, m); for (i=0; i<m; i++) cout<<a[i]<<" "; cout<< endl; return 0; } |
输入:5 4 -6 -11 6 -59 22 -6 1 10
输出:
3、阅读程序出结果:(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 27 28 29 |
#include <iostream> #include <cstring> using namespace std; int i,j,len; char s[50]; int main() { cin >>s; len = strlen(s); for (i = 0;i < len; ++i) { if (s[i] >= 'A' && s[i] <= 'Z') s[i] -= 'A' - 'a'; } for (i = 0;i < len; ++i) { if (s[i] < 'x') s[i] += 3; else s[i] += -23; } cout << s << '/'; for (j = 1;j < 4;j ++) { for (i = 0;i < len-j; i = i + j) { s[i] = s[i + j] ; } } cout << s << endl; return 0; } |
输入:ABCDEFGuvwxyz
输出:
4、阅读程序写出结果 (2009年真题)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> using namespace std; int main(){ int a[3],b[3]; int i,j,tmp; for (i=0;i<3;i++)cin >> b[i]; for (i=0;i<3;i++){ a[i]=0; for (j=0;j<=i;j++){ a[i]+=b[j]; b[a[i]%3]+=a[j]; } } tmp=1; for (i=0;i<3;i++){ a[i]%=10; b[i]%=10; tmp*=a[i]+b[i]; } cout << tmp << endl; return 0; } |
输入为:2 3 5 输出为:
5、阅读程序,输出结果: (2010年提高组)
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 main() { const int SIZE=10; int data[SIZE],i,j,cnt,n,m; cin>>n>>m; for(i=1;i<=n;i++) cin>>data[i]; for(i=1;i<=n;i++) { cnt=0; for(j=1;j<=n;j++) if( (data[i]<data[j]) || (data[j]==data[i] && j<i) ) cnt++; if (cnt==m) cout<<data[i]<<endl; } return 0; } |
输入:
5 2
96 -8 0 16 87
输出:
6、阅读程序写出结果: (2013年普及组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <iostream> using namespace std; int main() { const int SIZE = 100; int height[SIZE], num[SIZE], n, ans; cin>>n; for (int i = 0; i < n; i++) { cin>>height[i]; num[i] = 1; for (int j = 0; j < i; j++) { if ((height[j] < height[i]) && (num[j] >= num[i])) num[i] = num[j]+1; } } ans = 0; for (int i = 0; i < n; i++) { if (num[i] > ans) ans = num[i]; } cout<<ans<<endl; } |
输入:
6
2 5 3 11 12 4
输出:
7、阅读程序,根据输入结果,写出输出结果。 (2012年提高组)
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 |
#include <iostream> using namespace std; int n, i, temp, sum, a[100]; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n - 1; i++) if (a[i] > a[i + 1]) { temp = a[i]; a[i] = a[i + 1]; a[i + 1] = temp; } for (i = n; i >= 2; i--) if (a[i] < a[i - 1]) { temp = a[i]; a[i] = a[i - 1]; a[i - 1] = temp; } sum = 0; for (i = 2; i <= n - 1; i++) sum+= a[i]; cout << sum/(n-2) << endl; return 0; } |
输入:
8
40 70 50 70 20 40 10 30
输出:
8、阅读程序写结果 (2011年普及组)
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> #include<cstring> using namespace std; const int SIZE = 100; int main() { int n,i,sum,x,a[SIZE]; cin>>n; memset(a,0,sizeof(a)); for(i=1;i<=n;i++){ cin>>x; a[x]++; } i=0; sum=0; while(sum<(n/2+1)){ i++; sum+=a[i]; } cout<<i<<endl; return 0; } |
输入:
11
4 5 6 6 4 3 3 2 3 2 1
输出为:
9、阅读程序,输出结果 (2010年提高组)
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 27 |
#include<iostream> using namespace std; int main(){ const int SIZE=100; int na,nb,a[SIZE],b[SIZE],i,j,k; cin>>na; for(i=1;i<=na;i++)cin>>a[i]; cin>>nb; for(i=1;i<=nb;i++)cin>>b[i]; i=1; j=1; while( (i<=na)&&(j<=nb) ){ if(a[i]<=b[j]){ cout<<a[i]<<' '; i++; } else{ cout<<b[j]<<' '; j++; } } if(i<=na) for(k=i;k<=na;k++)cout<<a[k]<<' '; if(j<=nb) for(k=j;k<=nb;k++)cout<<b[k]<<' '; return 0; } |
输入:
5
1 3 5 7 9
4
2 6 10 14
输出: