對于一個n*n的稀疏矩陣M(1 <= n <= 1000),采用三元組順序表存儲表示,查找從鍵盤輸入的某個非零數(shù)據(jù)是否在稀疏矩陣中,如果存在則輸出OK,不存在則輸出ERROR。稀疏矩陣示例圖如下: Input 連續(xù)輸入多組數(shù)據(jù),每組數(shù)據(jù)的第一行是三個整數(shù)mu, nu, tu(tu<=50),分別表示稀疏矩陣的行數(shù)、列數(shù)和矩陣中非零元素的個數(shù),數(shù)據(jù)之間用空格間隔,隨后tu行輸入稀疏矩陣的非零元素所在的行、列值和非零元素的值,每組數(shù)據(jù)的最后一行輸入要查詢的數(shù)據(jù)k。 Output 輸出查詢結(jié)果,查找成功輸出OK,找不到輸出ERROR。 Example Input
3 5 51 2 141 5 -52 2 -73 1 363 4 2836Example Output
OKHint
Author xam
#include<stdio.h>#include <string.h>#include <stdlib.h>#define N 1010000int p[11000];int main(){ int m, n, t; while(~scanf("%d%d%d", &m, &n, &t)) { for(int a=0; a<t; a++) { scanf("%*d%*d%d", &p[a]); } int k; scanf("%d", &k); int a; for(a=0; a<t; a++) if(p[a]==k)break; if(a!=t)printf("OK/n"); else printf("ERROR/n"); } return 0;}新聞熱點
疑難解答