判断上三角矩阵
题目描述:https://www.nowcoder.com/practice/9a6786c28cdb45f9b991685f867b5d08?tpId=107&tags=&title=&diffculty=0&judgeStatus=0&rp=1&ru=/ta/beginner-programmers&qru=/ta/beginner-programmers/question-ranking
程序亮点:1.连续判断输入值2.利用break和continue快速判断,提高程序运行速度
#include <stdio.h> int main(void) { int i, j, n; int flag = 1; while (scanf("%d", &n) != EOF) { int a[n][n]; for (i = 0; i < n; i++) { for (j = 0; j < n ; j++) { scanf("%d", &a[i][j]); } } for (i = 0; i < n; i++) { for (j = 0; j < n ; j++) { if (i <= j) { break; } if (a[i][j] == 0) { continue; } else { flag = 0; break; } } if (flag == 0) { break; } } printf("%s\n", flag == 1 ? "YES" : "NO"); } return 0; }
程序亮点:利用二级指针
#include <iostream> using namespace std; int main() { int n = 0; int** list = NULL; cin >> n; list = new int*[n]; for(int i = 0; i < n; i++) list[i] = new int[n]; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> list[i][j]; bool isTrue = false; for(int i = 0; i < n; i++) for(int j = 0; j < i; j++) if(list[i][j] == 0) isTrue = true; else { isTrue = false; break; } if(isTrue) cout << "YES"; else cout << "NO"; return 0; }