ACM程序设计入门 考试题目

2019-09-01 10:05

《ACM程序设计入门》 考试题目

考试说明:

5 1 8 3

考试形式:提交A4纸双面手写报告 样例输出: 成绩评定:

55 153 及 格:交规范解题报告,并正确解题 1 1

不 及 格:报告雷同;不交报告;报告不符合204 46233 要求;其他…

14 9 优 秀:完成全部题目并现场答辩

报告要求:

源程序:

1、封皮格式自定,应包含内容如下:

#include 1)学号2)姓名3)班级 using namespace std ; 2、报告内容包含一下内容:

题目:给定

int Jiecheng( int n )//求n阶乘 分析:根据问题写出分析过程

{ 求解:根据分析过程设计程序的伪代码 int temp = 1 ; 代码:书写解题程序代码

if( !n ) 测试结果:给定几个符合题意的输入和输出 return temp ; 其他:可以分析算法的效率或者是其他对问题 for( int i = 1 ; i <= n ; i++ ) 的有效说明或解题的特色等等。 temp *= i ; 考试题目说明: return temp ; 考试题目共计10个题目,必须至少提交不少于}

8道题目的解题报告。报告中的题解少于8道其成绩int main() 评为不及格。想取得优秀成绩者报告必须提交10道{ 题目全部正确解,并现场答辩进行综合评定。 int n , sum1 , sum2 , i ; 考试题目如下:

while( cin >> n ) 题目一:给定正整数n,编程求出n个数的平方和及 { 阶乘和。

sum1 = sum2 = 0 ; 输入:多个正整数n

for( i = 1 ; i <= n ; i++) 输出:n个数的平方和与阶乘和,并用空格分开,每 { 个用例单独成行 sum1 += i*i ; 样例输入:

sum2 += Jiecheng( i ) ;

第1页 /共8页

}

cout << sum1 << ' ' << sum2 << endl ; } return 0 ; }

题目二:给定正整数n,编程求出不大于n的所有素数的和与所有素数的平均值。 输入:正整数n

输出:素数的和与素数的平均值,其中平均值要求保留2位小数 样例输入: 10 50 20 30 40 样例输出: 17 4.25 328 21.87 77 9.62 129 12.90 197 16.42

源程序:

#include #include using namespace std ;

bool Sushu( int n )//判断n是否为素数 { if( n <= 1 )

《ACM程序设计入门》 考试题目

return false ; int temp = n/2 ; for( int i = 2 ; i <= temp ; i++ ) { if( n % i == 0 && i!= n ) return false ; } return true ; }

int main() { double avg ; int i , n , sum , cnt; while( cin >> n ) { sum = cnt = 0 ; for( i = 2 ; i <= n ; i++ ) { if( Sushu( i ) ) { sum += i ; cnt++ ; } } avg = (double)sum / cnt ; cout << sum << ' ' << setprecision( 2 ) << fixed << avg << endl ; }

return 0 ; }

题目三:给定字符串,统计字符串中各字符出现的次数,并按照字符出现次数非降序输出字符和出现次数,次数相同按照字符序输出,最后将字符串逆序输出。

输入:字符串每个字符串长度不超过256

输出:每个字符出现的次数和逆序后的字符串 样例输入: Abcd

AAABBBBccDC 样例输出: A:1 b:1 c:1 d:1 dcbA B:4 A:3 c:2 C:1 D:1

CDccBBBBAAA

源程序:

#include #include

using namespace std ;

第2页 /共8页

struct Node { friend bool operator<( Node n1 , Node n2 ) { return n1.cnt < n2.cnt ; } int cnt ; char ch ; } ;

int main() { char str[300] ; int cnt[52] , len , index , i ; priority_queue q; Node*p ; while( gets( str ) ) { memset( cnt , 0 , sizeof cnt ) ; len = strlen( str ) ; for( i = 0 ; i < len ; i++ ) { if( str[i] >= 'a' ) index = str[i] - 'a' + 26 ; else index = str[i] - 'A' ; cnt[index] ++ ; } for( i = 0 ; i < 52 ; i++ ) if( cnt[i] > 0 )

《ACM程序设计入门》 考试题目

{ 2 1 6 p = new Node ; 3 4 5 p->cnt = cnt[i] ; 25 24 23 22 21 if( i < 26 ) 10 9 8 7 20 p->ch = (char)( 'A' + i ); 11 2 1 6 19 else p->ch = (char)( 'a' + i - 26 ) ; 12 3 4 5 18

y++ ; while( y < n && !A[y][x] ) A[y++][x] = cnt-- ; y-- ; x-- ; q.push( *p ) ; } while( !q.empty() ) { cout << q.top().ch << q.top().cnt << endl ; q.pop() ; } for( i = len -1 ; i >= 0 ; i-- ) cout << str[i] ; cout << endl ; } return 0 ; } 题目四:给定整数n,请输出蛇形矩阵。

输入:整数n

输出:蛇形矩阵

样例输入:

3 5 样例输出:

9 8 7 13 14 15 16 17 源程序: #include using namespace std ; ':' << void Snake( int n ) { int i , j ; int **A = new int*[n] ; for( i = 0 ; i < n ; i++ ) { A[i] = new int[n] ; for( j = 0 ; j < n ;j++ ) A[i][j] = 0 ; }

int x , y , num = n*n ; int cnt = num ; x = 0 , y = 0 ; while( cnt > 0 ) { while( x < n && !A[y][x] )

A[y][x++] = cnt-- ; x-- ;

第3页 /共8页

while( x >= 0 && !A[y][x] ) A[y][x--] = cnt-- ; x++ ; y-- ; while( y >= 0 && !A[y][x] ) A[y--][x] = cnt-- ; y++ ; x++ ; }

for( i = 0 ; i < n ; i++ ) { for( j = 0 ; j < n ; j++ ) cout << A[i][j] << ' ' ; cout << endl ; }

for( i = 0 ; i < n ; i++ ) delete []A[i] ; delete []A ;

}

《ACM程序设计入门》 考试题目

int main() { int n ; while( cin >> n ) Snake( n ) ; return 0 ; }

题目五:输出n位m进制的所有数字。输入:位数n,进制m 输出:n位m进制 样例输入: 3 2

样例输出: 000 001 010 011 100 101 110 111

源程序:

#include using namespace std ;

void print( int A[] , int n ) { for( int i = 0 ; i < n ; i++ ) cout << A[i] ; cout << endl ; }

void Enum( int A[] , int n , int m , int k ) { if( k == n ) print( A , n ) ; else { for( A[k] = 0 ; A[k] < m ; A[k]++ ) Enum( A , n , m , k+1 ) ; } }

int main() { int *A ; int n , m ; while( cin >> n >> m ) { A = new int[n] ; Enum( A , n , m , 0 ) ; delete []A ; } return 0 ;

第4页 /共8页

}

题目六:给定字符串,按照预定规则处理字符串的

转换。题目中给定翻译字典,请根据翻译字典对字符串进行翻译。例如给定翻译的规则为a->A b->B c->C….z->Z即将大小写的字符进行交换,如果输入了abcd则应该输出ABCD题目中将给定翻译用字典,如果没有在字典中找到符合要求的替换则用“_”替换翻译后的字符串。

输入:第一行为字典原文,第二行为字典翻译规则,第三行为待翻译的字符串 输出:翻译后的字符串 样例输入: abcd ABCD

CCCAADDBAA 1234abcd 9876abdc

00abAAdcc2371 样例输出: cccaaddbaa __ab__cdd87_9

源程序:

#include #include

using namespace std ;

int main() {

《ACM程序设计入门》 考试题目

string s1 , s2 , temp ; int i , j , k ; while( cin >> s1 && cin >> s2 ) { cin >> temp ; int len = temp.length() ; k = s1.length() ; for( i = 0 ; i < len ; i++ ) { for( j = 0 ; j < k ; j++ ) if( temp[i] == s1[j] ) { temp[i] = s2[j] ; break ; } if( j == k ) temp[i] = '_' ; } cout << temp << endl; } return 0 ;

}题目七:给定两个数,写程序求出两个数之和。输入:两个数,数的位数为1~500 输出:两个字的和 样例输入: 1000 2333

1111111111111111111111111 3333333333 样例输出: 3333 4444444444111111111111111 int temp = b[lenb--] - '0' + sum[index]

- '0' ; 源程序:

sum[index-1] += temp / 10 ; #include sum[index--] = temp % 10 + '0' ; using namespace std ; }

if( sum[index] == '0' ) int main() index ++ ; { for( int i = 0 ; index < 501 ; index++ , i++ ) const int n = 502 ; sum[i] = sum[index] ; char a[n] , b[n] , sum[n] ; sum[i] = '\\0' ; while( cin >> a >> b ) cout << sum << endl ; { memset( sum , '0' , sizeof sum ) ; } int lena = strlen( a ) - 1 , lenb = strlen( b ) return 0 ; -1 , index = 500 ; } while( lena >= 0 && lenb >= 0 ) {

int temp = a[lena--] - '0' + b[lenb--] - 题目八:成绩排序。给定n个同学(学号1..n)的m'0' + sum[index] - '0' ; 门课程的成绩,编程序排序输出学生的排序和成绩 sum[index-1] += temp / 10 ; 信息。排序规则,按照m门课程的平均成绩(取整) sum[index--] = temp % 10 + '0' ; 从高到低排序,如果平均成绩相同则名次相同。例 } 如有5名学生,其平均分为90、90、80、80、75则 while( lena >= 0 ) 排序后名次为11335

{ 输入:n表示n个学生,m表示每名学生有m个成 int temp = a[lena--] - '0' + sum[index] 绩,接下来是n行每行有m个成绩,成绩为100以- '0' ; 内的整数

sum[index-1] += temp / 10 ; 输出:学生的学号、名次、成绩和平均分 sum[index--] = temp % 10 + '0' ; 样例输入: } 3 5

while( lenb >= 0 ) 85 95 90 90 90 {

80 75 80 85 80

第5页 /共8页


ACM程序设计入门 考试题目.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2010-2011-2物理教学论B

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: