九度——題目1001: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
- 來源:
import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { Scanner cin = new Scanner(System.in); int a1[][], a2[][], rows, columns, count; boolean isZero; while (cin.hasNext()) { count = 0; rows = cin.nextInt(); if (rows == 0) { return; } columns = cin.nextInt(); // 開闢空間 a1 = new int[rows][]; for (int i = 0; i < rows; i++) { a1[i] = new int[columns]; } a2 = new int[rows][]; for (int i = 0; i < rows; i++) { a2[i] = new int[columns]; } // 輸入陣列 for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { a1[i][j] = cin.nextInt(); } } for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { a2[i][j] = cin.nextInt(); } } // 求和 for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { a1[i][j] = a1[i][j] + a2[i][j]; } } // 統計空行 for (int i = 0; i < rows; i++) { isZero = true; for (int j = 0; j < columns; j++) { if (a1[i][j] != 0) { isZero = false; } } if (isZero) { count++; } } // 統計空列 for (int j = 0; j < columns; j++) { isZero = true; for (int i = 0; i < rows; i++) { if (a1[i][j] != 0) { isZero = false; } } if (isZero) { count++; } } System.out.println(count); } } } /************************************************************** Problem: 1001 User: 憶、瞻 Language: Java Result: Accepted Time:1730 ms Memory:17992 kb ****************************************************************/
相關推薦
九度——題目1001: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. 輸入
【九度】題目1001: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. 輸入
九度oj 題目1001:A+B for Matrices 【ZJU2011考研機試題1】
題目1001:A+B for Matrices 時間限制:1 秒 記憶體限制:32 兆 特殊判題:否 提交:11539 解決:4694 題目描述: This time, you are supposed to find A+B where
九度考研真題 浙大 2011-1浙大1001:A+B for Matrices
//題目1001:A+B for Matrices #include<iostream> #include<string.h> using namespace std; int main() {int M,N;int a1[11][11],a2[11
九度題目1015還是A+B
#include<stdio.h> int main(){ int a,b,k,he,i,ai,bi; bool xiangdeng; while(scanf("%d%d%d",&a,&b,&k)!=EOF){ i
九度OJ 1003:A+B
時間限制:1 秒 記憶體限制:32 兆 特殊判題:否 提交:15078 解決:6299 題目描述: 給定兩個整數A和B,其表示形式是:從個位開始,每三位數用逗號","隔開。 現在請
九度OJ 題目1003:A+B
一.題目描述: 給定兩個整數A和B,其表示形式是:從個位開始,每三位數用逗號","隔開。 現在請計算A+B的結果,並以正常形式輸出。 輸入: 輸入包含多組資料資料,每組資料佔一行,由兩個整數A和B組成(-10^9 < A,B < 10^9)。 輸出: 請
九度題目1000:計算a+b
題目描述: 求整數a,b的和。 輸入: 測試案例有多行,每行為a,b的值。 輸出: 輸出多行,對應a+b的結果。 樣例輸入: 1 2 4 5 6 9 樣例輸出: 3 9
九度題目1015:還是A+B
題目描述: 讀入兩個小於10000的正整數A和B,計算A+B。需要注意的是:如果A和B的末尾K(不超過8)位數字相同,請直接輸出-1。 輸入: 測試輸入包含若干測試用例,每個測試用例佔一行,格式為"A B K",相鄰兩數字有一個空格間隔。當A和B同時為0時輸入結束,相應的
九度-題目1138:進制轉換
i++ 十進制 ring str 進制數 ble for 進制 進制轉換 http://ac.jobdu.com/problem.php?pid=1138 題目描述: 將一個長度最多為30位數字的十進制非負整數轉換為二進制數輸出。 輸入: 多組數據,每行為一個長度不超過
九度 題目1394:五連擊數組
ace 一個 using return include pop turn span printf 轉載請註明本文鏈接http://blog.csdn.net/yangnanhai93/article/details/40506571 題目鏈接:http://ac.job
九度-題目1214:醜數
得到 方法 產生 include pac number return clu n) http://ac.jobdu.com/problem.php?pid=1214 題目描述: 把只包含因子2、3和5的數稱作醜數(Ugly Number)。例如6、8都是醜數,但14不是,因
PAT乙級題目練習:A+B和C
//給定區間[-2的31次方, 2的31次方]內的3個整數A、B和C,請判斷A+B是否大於C。 #include <iostream> using namespace std; int main() { int m,i=1; long int a,
九度 題目1208:10進位制 VS 2進位制
#include <stdio.h> #include <string.h> char ch1[1000],ch2[4000]; //ch1儲存使用者輸入的10進位制大整數,ch2儲存ch1轉換後的翻轉的2進位制 int num[1000];//儲存ch2轉換的新的2進位制大整數! v
九度 題目1014:排名
按總分降序列印過錄取線的學生,總分相同時,id小的在前(id升序)。 程式碼: #include <vector> #include <algorithm> #include <iostream> #include <string
九度 題目1467:二叉排序樹
程式碼設計: #include <iostream> #include <algorithm> #include <stdio.h> using namespace
九度題目1008:最短路徑問題
題目描述: 給你n個點,m條無向邊,每條邊都有長度d和花費p,給你起點s終點t,要求輸出起點到終點的最短距離及其花費,如果最短距離有多條路線,則輸出花費最少的。 輸入: 輸入n,m,點的編號是1~n,然後是m行,每行4個數 a,b,d,p,表示a和b之間有一條邊,且其長度為
九度題目1434:今年暑假不AC
題目描述: “今年暑假不AC?”“是的。”“那你幹什麼呢?”“看世界盃呀,笨蛋!”“@#$%^&*%...”確實如此,世界盃來了,球迷的節日也來了,估計很多ACMer也會拋開電腦,奔向電視作為球迷,一定想看盡量多的完整的比賽,當然,作為新時代的好青年,你一定還會看
九度 題目1020:最小長方形
一.題目描述: 給定一系列2維平面點的座標(x, y),其中x和y均為整數,要求用一個最小的長方形框將所有點框在內。長方形框的邊分別平行於x和y座標軸,點落在邊上也算是被框在內。 輸入: 測試輸入包含若干測試用例,每個測試用例由一系列座標組成,每對座標佔
九度 題目1337:尋找最長合法括號序列
題目描述: 給你一個長度為N的,由’(‘和’)’組成的括號序列,你能找出這個序列中最長的合法括號子序列麼?合法括號序列的含義便是,在這個序列中,所有的左括號都有唯一的右括號匹配;所有的右括號都有唯一的左括號匹配。例如:((()))()()便是一個長度為10的合法括號序列,而