浙江大学11年计算机上机题(含答案).doc

  1. 1、本文档共23页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
浙江大学11年计算机上机题(含答案)

2011年 一、A+B for Matrices 题目描述: ??? This time, you are supposed to find A+B where A and B are two matrices, and then count the number of zero rows and columns. 输入: ??? The input consists of several test cases, each starts with a pair of positive integers M and N (≤10) which are the number of rows and columns of the matrices, respectively. Then 2*M lines follow, each contains N integers in [-100, 100], separated by a space. The first M lines correspond to the elements of A and the second M lines to that of B. ??? The input is terminated by a zero M and that case must NOT be processed. 输出: ??? For each test case you should output in one line the total number of zero rows and columns of A+B. 样例输入: 2 2 1 1 1 1 -1 -1 10 9 2 3 1 2 3 4 5 6 -1 -2 -3 -4 -5 -6 0 样例输出: 1 5 答案: 考虑输入m=n=1时在网上找了一段代码,粘到到九度OJ上就AC了,并且它的运行结果在m=n=1时,如果结果是0,得到的结果是2。这是已经AC的代码: #includestdio.h #includestdlib.h int n, m; int a[15][15]; int main() { ? ? int i, j, b, cnt; ? ? while(scanf(%d, n), n) { ? ?? ???scanf(%d, m); ? ?? ???for(i = 0; i n; ++i) { ? ?? ?? ?? ?for(j = 0; j m; ++j) { ? ?? ?? ?? ?? ? scanf(%d, a[i][j]); ? ?? ?? ?? ?} ? ?? ???} ? ?? ???for(i = 0 ; i n; ++i) { ? ?? ?? ?? ?for(j = 0; j m; ++j) { ? ?? ?? ?? ?? ? scanf(%d, b); ? ?? ?? ?? ?? ? a[i][j] +=b; ? ?? ?? ?? ?} ? ?? ???} ? ?? ???cnt = 0; ? ?? ???for(i = 0; i n; ++i) { ? ?? ?? ?? ?for(j = 0; j m; ++j) { ? ?? ?? ?? ?? ? if(a[i][j] != 0 ) break; ? ?? ?? ?? ?} ? ?? ?? ?? ?if(j == m) ++cnt; ? ?? ???} ? ?? ???for(i = 0; i m; ++i) { ? ?? ?? ?? ?for(j = 0; j n; ++j) { ? ?? ?? ?? ?? ? if(a[j][i] != 0 ) break; ? ?? ?? ?? ?} ? ?? ?? ?? ?if(j == n) ++cnt; ? ?? ???} ? ?? ???printf(%d\n, cnt); ? ? } ? ? return 0; } 复制代码 然后,我自己的代码是这样的,我实在是想不明白,为什么它通过了,我的还是WA。 #includeiostream using namespace std; int main() { ? ? ? ? int a[15][15],temp; ? ? ? ? int m,n; ? ? ? ? int i,j; ? ? ? ? int flag; ? ? ? ? int ans; ? ? ? ? ? ? ? ? while((cinm),m) ? ? ? ? { ? ? ? ? ? ? ? ? cinn; ? ? ? ? ? ? ? ? ans=0; ? ? ? ? ? ? ? ? for(i=0;im;i++) ? ? ? ? ? ? ?

文档评论(0)

yan698698 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档