NOIP(六)
1 #include <iostream>
2 #include <cstring>
3 #include <cstdio>
4 using namespace std;
5 /**
6 鞍点 标志位
7 4 4
8 4 32 2 1
9 5 10 5 2
10 6 13 6 3
11 7 14 1 3
12
13 4
14
15 // 11 3 5 6 9
16 // 12 4 7 8 10
17 // 10 5 6 9 11
18 // 8 6 4 7 2
19 // 15 10 11 20 25
20
21 测试样例:
22
23 */
24 int main(){
25 int m,n,xmax = 0,ymin = 999;
26 bool q;
27 //输入
28 cin >> m >> n;
29 int a[m + 1][n + 1];
30 for(int i = 1; i <= m;i++){
31 for(int j = 1;j <= n;j++){
32 cin >> a[i][j];
33 }
34 }
35 //算法
36 int x,y;//最大值的位置所在的行和列
37 for(int i = 1;i <= m;i++){
38 xmax = 0;
39 q = true;
40 //比较行
41 for(int j = 1;j <= n;j++){
42 if(a[i][j] > xmax){
43 xmax = a[i][j];
44 x = i;
45 y = j;
46 }
47 }
48 //比较列
49 for(int j = 1;j <= m;j++){
50 //怎么判断就是当前最大值所在的列
51 if(a[j][y] < xmax){//当最大值所在的列中有比最大值小的数,该标志位定义为false
52 q = false;
53 }
54 }
55 //当q为true时,该鞍点数已经产生
56 if(q == true){
57 cout << "行所在的位置:" << x << "\n" <<
58 "列所在的位置是:" << y << "\n" << "鞍点值:" << a[x][y] << endl;
59 }
60 }
61 return 0;
62 }
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5 /**
6 求矩阵鞍点
7 鞍点解释:
8 所谓鞍点指的是:矩阵中鞍点的值为所在行的最大值,为所在列的最小值。
9
10 4 5
11 10 9 8 7 6
12 11 8 9 7 1
13 12 9 10 11 12
14 13 14 8 6 7
15
16 10
17 */
18 int main(){
19 int m,n;
20 //一、输出
21 cin >> m >> n;//获取矩阵的高长
22 int a[m + 1][n + 1];
23 for(int i = 1;i <= m;i++){//循环行
24 for(int j = 1;j <= n;j++){//循环列
25 cin >> a[i][j];
26 }
27 }
28 //算法
29 int x,y,xmax = 0;
30 bool q = false;//标志位
31 for(int i = 1;i <= m;i++){//循环行
32 q = true;//一开始循环的时候每个位置上的标志位都是true
33 for(int j = 1;j <= n;j++){
34 if(a[i][j] > xmax){//寻找最大值
35 xmax = a[i][j];//最大值
36 x = i;//行下标
37 y = j;//列下标
38 }
39 }
40 //找该列中最小的数
41 for(int j = 1;j <= m;j++){
42 if(a[j][y] < xmax){//不是行最大值所在列的最小值
43 q = false;//标志位改为false
44 }
45 }
46 //当整个列都判断完成以后
47 if(q){//如果当前行最大值所在的列的较小值还有标志为true
48 cout << "鞍点的行是:" << x << "\n鞍点的列是:" << y << "\n鞍点值是:" << a[x][y];
49 }
50 }
51 return 0;
52 }
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5 /**
6 图像相似程度
7 二个m*n的矩阵,比较矩阵的相似程度
8 输入:
9 4 5
10 1 8 9 5 9
11 2 4 5 7 8
12 1 3 6 7 0
13 2 3 7 8 9
14
15 1 2 9 3 9
16 2 4 6 7 8
17 1 3 7 7 6
18 2 2 7 8 1
19
20 输出:相似度
21 65.00%
22 */
23 int main(){
24 int m,n,c = 0;
25 cin >> m >> n;
26 int a[m + 1][n + 1];
27 int b[m + 1][n + 1];
28 //第一个矩阵输入
29 for(int i = 1;i <= m;i++){
30 for(int j = 1;j <= n;j++){
31 cin >> a[i][j];
32 }
33 }
34 //第二个矩阵输入
35 for(int i = 1;i <= m;i++){
36 for(int j = 1;j <= n;j++){
37 cin >> b[i][j];
38 //判断两个矩阵上是否有相同元素,若有则计数器+1
39 if(a[i][j] == b[i][j]){
40 c++;
41 }
42 }
43 }
44 //输出
45 printf("%.2lf %s",c/(m*n*1.0) * 100,"%");
46 return 0;
47 }
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5 /**
6 字符和字符序列
7
8 输入一个整数表示字符的个数和一串字符,请判断字符集中存在的数字的个数
9 输入:
10 8
11 NOIP2020
12 输出:
13 4
14 */
15 int main(){
16 int n,c = 0;
17 cin >> n;
18 char a[n + 1];
19 for(int i = 0;i < n;i++){
20 cin >> a[i];
21 //算法
22 if(a[i] >= '0' && a[i] <= '9'){
23 c++;
24 }
25 }
26 //str = string len = length
27 cout << strlen(a) << endl;
28
29 return 0;
30 }
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5 /**
6 找第一个只出现一次的字符
7 输入:
8 abcabd
9 输出:
10 c
11
12 */
13 int main(){
14 char a[10001];
15 gets(a);
16 int l = strlen(a);
17 int c;
18 //求取字符是否相同,若相同则计数器累加
19 for(int i = 0;i < l;i++){
20 //计数器c
21 c = 0;
22 for(int j = 0;j < l;j++){
23 if(a[i] == a[j]){
24 c++;
25 }
26 }
27 //获取只出现一次的字符
28 if(c == 1){
29 cout << a[i];
30 break;//exit(0);
31 }
32 }
33 return 0;
34 }
代码虐我千百遍,我待代码如初恋!--gogo-BUG!
吃过符号的亏,上过大小写的当!--gogo-DEBUG!


浙公网安备 33010602011771号