提交 69d23ffc 编写于 作者: 每日一练社区's avatar 每日一练社区

update dailycode code variant gen

上级 3c76afa0
...@@ -23,7 +23,7 @@ int main() ...@@ -23,7 +23,7 @@ int main()
} }
j = j1 + j2 + shiftj; j = j1 + j2 + shiftj;
_____________________ _____________________;
y = y1 + y2 + shifty; y = y1 + y2 + shifty;
ss = y + j/10.0 + f/100.0; ss = y + j/10.0 + f/100.0;
......
...@@ -35,7 +35,7 @@ int main() ...@@ -35,7 +35,7 @@ int main()
else else
a[10]++; a[10]++;
} }
________________ ________________;
} }
``` ```
......
...@@ -24,7 +24,7 @@ int main() ...@@ -24,7 +24,7 @@ int main()
for (i = 0; i < n - 2; i++) for (i = 0; i < n - 2; i++)
{ {
double exp = a2 / b2; double exp = a2 / b2;
_____________________ _____________________;
sum += exp; sum += exp;
double a = a1 + a2; double a = a1 + a2;
double b = b1 + b2; double b = b1 + b2;
......
...@@ -36,7 +36,7 @@ int main() ...@@ -36,7 +36,7 @@ int main()
a[i].push_back('A' + j + p); a[i].push_back('A' + j + p);
b[i] = a[i]; b[i] = a[i];
reverse(b[i].begin(), b[i].end()); reverse(b[i].begin(), b[i].end());
___________________ ___________________;
p++; p++;
} }
p = 0; p = 0;
......
...@@ -28,7 +28,7 @@ int main() ...@@ -28,7 +28,7 @@ int main()
scanf("%d %d", &n, &m); scanf("%d %d", &n, &m);
m = m % n; m = m % n;
int count = m; int count = m;
______________ ______________;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
scanf("%d", &a[i]); scanf("%d", &a[i]);
int first = 1; int first = 1;
......
...@@ -12,7 +12,7 @@ int isPrime(int n) ...@@ -12,7 +12,7 @@ int isPrime(int n)
int i; int i;
if (n < 2) if (n < 2)
return 0; return 0;
_______________ _______________;
return 1; return 1;
} }
int CountPrime(int a[], int size) int CountPrime(int a[], int size)
......
...@@ -24,7 +24,7 @@ int main() ...@@ -24,7 +24,7 @@ int main()
{ {
printf("\n请输入购货金额:\n"); printf("\n请输入购货金额:\n");
scanf("%f", &money); scanf("%f", &money);
____________________ ____________________;
} }
return 0; return 0;
} }
......
...@@ -32,7 +32,7 @@ int main() ...@@ -32,7 +32,7 @@ int main()
b[i] = a[i]; b[i] = a[i];
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
__________________ __________________;
} }
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
printf("%d\n", a[i]); printf("%d\n", a[i]);
......
...@@ -51,7 +51,7 @@ int main() ...@@ -51,7 +51,7 @@ int main()
{ {
if (arr[j] > arr[j + 1]) if (arr[j] > arr[j + 1])
{ {
____________________ ____________________;
} }
} }
for (int j = 0; j < n; j++) for (int j = 0; j < n; j++)
......
...@@ -27,7 +27,7 @@ int main() ...@@ -27,7 +27,7 @@ int main()
x = i; x = i;
while (x > 0) while (x > 0)
{ {
________________ ________________;
} }
score += temp; score += temp;
} }
......
...@@ -20,7 +20,7 @@ int main(){ ...@@ -20,7 +20,7 @@ int main(){
if(i==0) if(i==0)
min = a[i]; min = a[i];
sum+=a[i]; sum+=a[i];
____________ ____________;
} }
ave=sum/10; ave=sum/10;
for(i=0;i<5;i++) for(i=0;i<5;i++)
......
...@@ -52,7 +52,7 @@ int main() ...@@ -52,7 +52,7 @@ int main()
num = a * b; num = a * b;
printf("%d\n", num); printf("%d\n", num);
} }
_________________________ _________________________;
else else
{ {
printf("%s\n", "WA"); printf("%s\n", "WA");
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
using namespace std; using namespace std;
int diff(char ch1, char ch2) int diff(char ch1, char ch2)
{ {
__________________ __________________;
} }
int main() int main()
{ {
......
...@@ -49,7 +49,7 @@ int main() ...@@ -49,7 +49,7 @@ int main()
{ {
for (int j = i + 1; j < n; j++) for (int j = i + 1; j < n; j++)
{ {
__________________ __________________;
} }
} }
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
......
...@@ -36,7 +36,7 @@ int main() ...@@ -36,7 +36,7 @@ int main()
{ {
if (b[j] == a[k]) if (b[j] == a[k])
{ {
__________________ __________________;
} }
} }
} }
......
...@@ -17,7 +17,7 @@ int main() ...@@ -17,7 +17,7 @@ int main()
if (c >= 'A' && c <= 'z') if (c >= 'A' && c <= 'z')
{ {
m = c - 'A' + 1; m = c - 'A' + 1;
_____________________ _____________________;
} }
if (n > 0) if (n > 0)
printf("%c在第%d个位置,其后面第四个字母是%c\n", c, m, c2); printf("%c在第%d个位置,其后面第四个字母是%c\n", c, m, c2);
......
...@@ -12,7 +12,7 @@ int oneNum(int x) ...@@ -12,7 +12,7 @@ int oneNum(int x)
int cnt = 0; int cnt = 0;
while(x) while(x)
{ {
____________ ____________;
} }
return cnt; return cnt;
} }
......
...@@ -21,7 +21,7 @@ int main() ...@@ -21,7 +21,7 @@ int main()
a = n % 1000 / 100; a = n % 1000 / 100;
b = n % 100 / 10; b = n % 100 / 10;
c = n % 10 / 1; c = n % 10 / 1;
___________________ ___________________;
if (y == n) if (y == n)
cout << n << "是水仙花数" << endl; cout << n << "是水仙花数" << endl;
else else
......
...@@ -29,7 +29,7 @@ int main() ...@@ -29,7 +29,7 @@ int main()
{ {
scanf("%d", &n); scanf("%d", &n);
int s, f, m; int s, f, m;
____________ ____________;
print(s); print(s);
printf(":"); printf(":");
print(f); print(f);
......
...@@ -36,7 +36,7 @@ int main() ...@@ -36,7 +36,7 @@ int main()
int a[256] = {0}; int a[256] = {0};
bool flag = false; bool flag = false;
for (int i = 0; i < str.size(); ++i) for (int i = 0; i < str.size(); ++i)
____________________ ____________________;
for (int i = 0; i < str.size(); ++i) for (int i = 0; i < str.size(); ++i)
{ {
if (a[str[i]] == 1) if (a[str[i]] == 1)
......
...@@ -19,7 +19,7 @@ int main() ...@@ -19,7 +19,7 @@ int main()
ave = sum * 1.0 / n; ave = sum * 1.0 / n;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
__________________ __________________;
} }
return 0; return 0;
} }
......
...@@ -19,7 +19,7 @@ int main(){ ...@@ -19,7 +19,7 @@ int main(){
scanf("%d %lf", &fruit, &amount); scanf("%d %lf", &fruit, &amount);
purchase = (fruits)fruit; purchase = (fruits)fruit;
________________________ ________________________;
return 0; return 0;
} }
......
...@@ -26,12 +26,7 @@ int fun(int n, int *x, int *y) ...@@ -26,12 +26,7 @@ int fun(int n, int *x, int *y)
size = 2 * (*x) - 1; size = 2 * (*x) - 1;
dd = (*x); dd = (*x);
for (i = 2; i <= (*y); i++) for (i = 2; i <= (*y); i++)
{ __________________________;
if (i <= (*x))
dd *= 2;
else
dd /= 2;
}
return dd; return dd;
} }
else else
...@@ -58,7 +53,13 @@ int main() ...@@ -58,7 +53,13 @@ int main()
## 答案 ## 答案
```cpp ```cpp
for (i = 2; i <= (*y); i++)
{
if (i <= (*x))
dd *= 2;
else
dd /= 2;
}
``` ```
## 选项 ## 选项
...@@ -66,17 +67,35 @@ int main() ...@@ -66,17 +67,35 @@ int main()
### A ### A
```cpp ```cpp
for (i = 2; i <= (*y); i++)
{
if (i <= (*x))
dd /= 2;
else
dd *= 2;
}
``` ```
### B ### B
```cpp ```cpp
for (i = 2; i <= (*y); i++)
{
if (i <= (*x))
dd += 2;
else
dd -= 2;
}
``` ```
### C ### C
```cpp ```cpp
for (i = 2; i <= (*y); i++)
{
if (i <= (*x))
dd -= 2;
else
dd += 2;
}
``` ```
\ No newline at end of file
...@@ -13,7 +13,7 @@ int solve(string s) ...@@ -13,7 +13,7 @@ int solve(string s)
if (s.length() == 0) return 0; if (s.length() == 0) return 0;
int n = 0; int n = 0;
for (int i = 1; i < s.length(); i++) for (int i = 1; i < s.length(); i++)
if (s.c_str()[i] < s.c_str()[i - 1]) n++; ___________________;
return n; return n;
} }
int main() int main()
...@@ -28,7 +28,7 @@ int main() ...@@ -28,7 +28,7 @@ int main()
## 答案 ## 答案
```cpp ```cpp
if (s.c_str()[i] < s.c_str()[i - 1]) n++;
``` ```
## 选项 ## 选项
...@@ -36,17 +36,17 @@ int main() ...@@ -36,17 +36,17 @@ int main()
### A ### A
```cpp ```cpp
if (s.c_str()[i] > s.c_str()[i - 1]) n++;
``` ```
### B ### B
```cpp ```cpp
if (s.c_str()[i] < s.c_str()[i + 1]) n++;
``` ```
### C ### C
```cpp ```cpp
if (s.c_str()[i] > s.c_str()[i + 1]) n++;
``` ```
\ No newline at end of file
...@@ -10,41 +10,52 @@ ...@@ -10,41 +10,52 @@
## template ## template
```cpp ```cpp
#include "stdio.h" #include "stdio.h"
int main(){ int main()
int score; {
scanf("%d",&score); int score;
if(score>=95){ scanf("%d", &score);
printf("A\n"); if (score >= 95)
}else if(score>=85 && score<=94){ {
printf("B\n"); printf("A\n");
}else if(score>=75 && score<=84){ }
printf("C\n"); else if (score >= 85 && score <= 94)
}else if(score>=65 && score<=74){ {
printf("D\n"); printf("B\n");
}else{ }
printf("E\n"); else if (score >= 75 && score <= 84)
} {
printf("以下用switch语句实现相同功能\n"); printf("C\n");
score = score-5; }
score = score/10; else if (score >= 65 && score <= 74)
switch(score){ {
case 9: printf("D\n");
printf("A\n"); }
break; else
case 8: {
printf("B"); printf("E\n");
break; }
case 7: printf("以下用switch语句实现相同功能\n");
printf("C\n"); score = score - 5;
break; score = score / 10;
case 6: switch (score)
printf("D\n"); {
break; case 9:
default: printf("A\n");
printf("E\n"); break;
break; case 8:
} printf("B");
break;
case 7:
printf("C\n");
break;
case 6:
printf("D\n");
break;
default:
printf("E\n");
break;
}
} }
``` ```
......
...@@ -13,7 +13,7 @@ int isp(int n) ...@@ -13,7 +13,7 @@ int isp(int n)
return 0; return 0;
for (i=2;i*i<=n;++i) for (i=2;i*i<=n;++i)
{ {
_______________ _______________;
} }
return 1; return 1;
} }
......
...@@ -46,7 +46,7 @@ void merge(int * a1, int m, int * a2, int n) ...@@ -46,7 +46,7 @@ void merge(int * a1, int m, int * a2, int n)
{ {
if (m1 < 0) a1[i] = a2[n1--]; if (m1 < 0) a1[i] = a2[n1--];
else if (n1 < 0) a1[i] = a1[m1--]; else if (n1 < 0) a1[i] = a1[m1--];
__________________ __________________;
} }
} }
int main() int main()
......
...@@ -13,12 +13,12 @@ int main() ...@@ -13,12 +13,12 @@ int main()
scanf("%c",&x); scanf("%c",&x);
if(x>='A'&&x<='Z') if(x>='A'&&x<='Z')
{ {
(1)___________ (1)___________;
printf("此字母是一个大写字母,转换后的小写字母是:%c",y); printf("此字母是一个大写字母,转换后的小写字母是:%c",y);
} }
else if(x>='a'&&x<='z') else if(x>='a'&&x<='z')
{ {
(2)___________ (2)___________;
printf("此字母是一个小写字母,转换后的大写字母是%c",y); printf("此字母是一个小写字母,转换后的大写字母是%c",y);
} }
else else
......
...@@ -32,7 +32,7 @@ int isprime(int n) ...@@ -32,7 +32,7 @@ int isprime(int n)
int i; int i;
if(n<=1) return 0; if(n<=1) return 0;
for(i=2;i*i<=n;i++) for(i=2;i*i<=n;i++)
_______________ _______________;
return 1; return 1;
} }
``` ```
......
...@@ -21,7 +21,7 @@ int main() ...@@ -21,7 +21,7 @@ int main()
scanf("%d",&a[i]); scanf("%d",&a[i]);
for(i=0;i<n;i++){ for(i=0;i<n;i++){
for(j=0;j<n;j++){ for(j=0;j<n;j++){
_____________ _____________;
} }
} }
for(i=0;i<n;i++) for(i=0;i<n;i++)
......
...@@ -14,45 +14,45 @@ defghijkabc ...@@ -14,45 +14,45 @@ defghijkabc
## template ## template
```cpp ```cpp
#include<iostream> #include <iostream>
#include <string.h> #include <string.h>
using namespace std; using namespace std;
void reverse(char *a,int start, int end) void reverse(char *a, int start, int end)
{ {
int i ,j,temp; int i, j, temp;
for(i = start,j = end; i < j; i++,j--) for (i = start, j = end; i < j; i++, j--)
{ {
temp = a[i]; temp = a[i];
a[i] = a[j]; a[i] = a[j];
a[j] = temp; a[j] = temp;
} }
} }
void turnleft(char *a,int i,int n) void turnleft(char *a, int i, int n)
{ {
int left = i % n; int left = i % n;
if(left == 0) if (left == 0)
return ; return;
reverse(a,0,left-1); ______________
reverse(a,left,n-1); return;
reverse(a,0,n-1);
return ;
} }
int main() int main()
{ {
char a[1024]; char a[1024];
int i; int i;
cin>>i; cin >> i;
cin>>a; cin >> a;
int n = strlen(a); int n = strlen(a);
turnleft(a,i,n); turnleft(a, i, n);
cout<<a<<endl; cout << a << endl;
} }
``` ```
## 答案 ## 答案
```cpp ```cpp
reverse(a, 0, left - 1);
reverse(a, left, n - 1);
reverse(a, 0, n - 1);
``` ```
## 选项 ## 选项
...@@ -60,17 +60,20 @@ int main() ...@@ -60,17 +60,20 @@ int main()
### A ### A
```cpp ```cpp
reverse(a, left, n - 1);
reverse(a, 0, n - 1);
``` ```
### B ### B
```cpp ```cpp
reverse(a, 0, left - 1);
reverse(a, left, n - 1);
``` ```
### C ### C
```cpp ```cpp
reverse(a, 0, left - 1);
reverse(a, 0, n - 1);
``` ```
\ No newline at end of file
...@@ -24,32 +24,34 @@ ...@@ -24,32 +24,34 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
int result[10]; int result[10];
int main(void) { int main(void)
memset(result, 0, sizeof(int) * 10); {
int n; memset(result, 0, sizeof(int) * 10);
int arr[10]; int n;
while (scanf("%d", &n) != EOF) int arr[10];
{ while (scanf("%d", &n) != EOF)
memset(arr, 0, sizeof(int) * 10); {
if (n == 0) arr[0] = 1; memset(arr, 0, sizeof(int) * 10);
while (n > 0) if (n == 0)
{ arr[0] = 1;
arr[n % 10] = 1; while (n > 0)
n = n / 10; {
} ____________
for (int i = 0; i < 10; i++) }
result[i] += arr[i]; for (int i = 0; i < 10; i++)
} result[i] += arr[i];
for (int i = 0; i < 10; i++) }
printf("%d: %d\n", i, result[i]); for (int i = 0; i < 10; i++)
return 0; printf("%d: %d\n", i, result[i]);
return 0;
} }
``` ```
## 答案 ## 答案
```cpp ```cpp
arr[n % 10] = 1;
n = n / 10;
``` ```
## 选项 ## 选项
...@@ -57,17 +59,20 @@ int main(void) { ...@@ -57,17 +59,20 @@ int main(void) {
### A ### A
```cpp ```cpp
arr[n % 10] = 1;
n = n % 10;
``` ```
### B ### B
```cpp ```cpp
arr[n / 10] = 1;
n = n / 10;
``` ```
### C ### C
```cpp ```cpp
arr[n % 10] = 1;
n++;
``` ```
\ No newline at end of file
...@@ -12,29 +12,29 @@ EDCBABC ...@@ -12,29 +12,29 @@ EDCBABC
## template ## template
```cpp ```cpp
#include<stdio.h> #include <stdio.h>
#include<math.h> #include <math.h>
int main() int main()
{ {
int m,n; int m, n;
scanf("%d%d",&n,&m); scanf("%d%d", &n, &m);
int i,j; int i, j;
for(i=0;i<n;i++) for (i = 0; i < n; i++)
{ {
for(j=0;j<m;j++) for (j = 0; j < m; j++)
{ {
printf("%c",65+abs(i-j)); ______________
} }
printf("\n"); printf("\n");
} }
return 0; return 0;
} }
``` ```
## 答案 ## 答案
```cpp ```cpp
printf("%c", 65 + abs(i - j));
``` ```
## 选项 ## 选项
...@@ -42,17 +42,17 @@ int main() ...@@ -42,17 +42,17 @@ int main()
### A ### A
```cpp ```cpp
printf("%c", 65 + i - j);
``` ```
### B ### B
```cpp ```cpp
printf("%c", 65 + i + j);
``` ```
### C ### C
```cpp ```cpp
printf("%c", 65 - i + j);
``` ```
\ No newline at end of file
...@@ -11,33 +11,33 @@ ...@@ -11,33 +11,33 @@
#include <stdio.h> #include <stdio.h>
int main() int main()
{ {
int a[10],i,n; int a[10], i, n;
int isfind = 0; int isfind = 0;
printf("please set array values:"); printf("please set array values:");
for(i=0;i<10;i++) for (i = 0; i < 10; i++)
scanf("%d",&a[i]); scanf("%d", &a[i]);
printf("please enter one num:"); printf("please enter one num:");
scanf("%d",&n); scanf("%d", &n);
for (i=0;i<10;i++) for (i = 0; i < 10; i++)
{ {
if(a[i] < n) ______________
{ }
isfind = 1; if (isfind)
printf("%d ",a[i]); printf("\n");
} else
} printf("not find\n");
if(isfind) return 0;
printf("\n");
else
printf("not find\n");
return 0;
} }
``` ```
## 答案 ## 答案
```cpp ```cpp
if (a[i] < n)
{
isfind = 1;
printf("%d ", a[i]);
}
``` ```
## 选项 ## 选项
...@@ -45,17 +45,29 @@ int main() ...@@ -45,17 +45,29 @@ int main()
### A ### A
```cpp ```cpp
if (a[i] < n)
{
isfind = 0;
printf("%d ", a[i]);
}
``` ```
### B ### B
```cpp ```cpp
if (a[i] > n)
{
isfind = 1;
printf("%d ", a[i]);
}
``` ```
### C ### C
```cpp ```cpp
if (a[i] > n)
{
isfind = 0;
printf("%d ", a[i]);
}
``` ```
\ No newline at end of file
...@@ -19,44 +19,45 @@ ...@@ -19,44 +19,45 @@
```cpp ```cpp
#include <stdio.h> #include <stdio.h>
int main () int main()
{ {
int a[6][6]; int a[6][6];
int m,n; int m, n;
int i,j; int i, j;
int max; int max;
int indexx=0,indexy=0; int indexx = 0, indexy = 0;
scanf("%d %d",&m,&n); scanf("%d %d", &m, &n);
for (i = 0;i<m;i++) for (i = 0; i < m; i++)
{ {
for (j = 0;j<n;j++) for (j = 0; j < n; j++)
{ {
scanf("%d",&a[i][j]); scanf("%d", &a[i][j]);
if(i == 0 && j==0) if (i == 0 && j == 0)
{ {
max = a[i][j]; max = a[i][j];
indexx = 0; indexx = 0;
indexy = 0; indexy = 0;
}else }
{ else
if (a[i][j] > max) {
{ _____________
max = a[i][j]; }
indexx = i; }
indexy = j; }
} printf("%d,%d,%d\n", max, indexx, indexy);
} return 0;
}
}
printf("%d,%d,%d\n",max,indexx,indexy);
return 0;
} }
``` ```
## 答案 ## 答案
```cpp ```cpp
if (a[i][j] > max)
{
max = a[i][j];
indexx = i;
indexy = j;
}
``` ```
## 选项 ## 选项
...@@ -64,17 +65,32 @@ int main () ...@@ -64,17 +65,32 @@ int main ()
### A ### A
```cpp ```cpp
if (a[i][j] < max)
{
max = a[i][j];
indexx = i;
indexy = j;
}
``` ```
### B ### B
```cpp ```cpp
if (a[i][j] > max)
{
max = a[i][j];
indexx = j;
indexy = i;
}
``` ```
### C ### C
```cpp ```cpp
if (a[i][j] <= max)
{
max = a[i][j];
indexx = i;
indexy = j;
}
``` ```
\ No newline at end of file
...@@ -10,31 +10,35 @@ B=1 C=5 ...@@ -10,31 +10,35 @@ B=1 C=5
```cpp ```cpp
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
int main () { int main()
float A = 0.2f; {
int x = 0; float A = 0.2f;
if (A < 0) { x = 1; A = 1/A; } int x = 0;
float delta = 1; if (A < 0)
int B = 1, C = 1; {
do x = 1;
{ A = 1 / A;
C = (int)(B * A); }
delta = fabs(C/(float)B-A); float delta = 1;
B++; int B = 1, C = 1;
} do
while (delta > 0.000001); {
if (x == 0) ____________
printf("%d / %d", C, B - 1); } while (delta > 0.000001);
else if (x == 0)
printf("%d / %d", B - 1, C); printf("%d / %d", C, B - 1);
return 0; else
printf("%d / %d", B - 1, C);
return 0;
} }
``` ```
## 答案 ## 答案
```cpp ```cpp
C = (int)(B * A);
delta = fabs(C / (float)B - A);
B++;
``` ```
## 选项 ## 选项
...@@ -42,17 +46,23 @@ int main () { ...@@ -42,17 +46,23 @@ int main () {
### A ### A
```cpp ```cpp
C = B * A;
delta = fabs(C / (float)B - A);
B++;
``` ```
### B ### B
```cpp ```cpp
C = B * A;
delta = fabs(C / B - A);
B++;
``` ```
### C ### C
```cpp ```cpp
C = B * A;
delta = fabs(C / (float)B - A);
B++;
``` ```
\ No newline at end of file
...@@ -3,11 +3,15 @@ ...@@ -3,11 +3,15 @@
题目描述 题目描述
编写以下函数: 编写以下函数:
(1)在一个二维数组中形成以下形式的n阶矩阵: (1)在一个二维数组中形成以下形式的n阶矩阵:
```json
[1 1 1 1 1 [1 1 1 1 1
2 1 1 1 1 2 1 1 1 1
3 2 1 1 1 3 2 1 1 1
4 3 2 1 1 4 3 2 1 1
5 4 3 2 1] 5 4 3 2 1]
```
(2)去掉靠边的元素,生成新的n-2阶矩阵; (2)去掉靠边的元素,生成新的n-2阶矩阵;
(3)求生成的n阶矩阵主对角线上的元素之和; (3)求生成的n阶矩阵主对角线上的元素之和;
(4)以方阵形式输出数组。 (4)以方阵形式输出数组。
...@@ -20,15 +24,22 @@ ...@@ -20,15 +24,22 @@
5 5
样例输出 样例输出
Generated matrix: Generated matrix:
```json
1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 2 1 1 1 1
3 2 1 1 1 3 2 1 1 1
4 3 2 1 1 4 3 2 1 1
5 4 3 2 1 5 4 3 2 1
```
del the elements on the side: del the elements on the side:
```json
1 1 1 1 1 1
2 1 1 2 1 1
3 2 1 3 2 1
```
The sum of the diagonal:5 The sum of the diagonal:5
...@@ -36,47 +47,49 @@ The sum of the diagonal:5 ...@@ -36,47 +47,49 @@ The sum of the diagonal:5
```cpp ```cpp
#include <iostream> #include <iostream>
using namespace std; using namespace std;
int main() { int main()
while(1){ {
int a; while (1)
cin>>a; {
int array[a][a]; int a;
for (int i=0;i<a;i++) cin >> a;
for (int j=0;j<a;j++) int array[a][a];
{ for (int i = 0; i < a; i++)
if(j<i) for (int j = 0; j < a; j++)
array[i][j]=i+1-j; {
else if (j < i)
array[i][j]=1; array[i][j] = i + 1 - j;
} else
cout<<"Generated matrix:"<<endl; array[i][j] = 1;
for (int i=0;i<a;i++) }
{ cout << "Generated matrix:" << endl;
for (int j=0;j<a;j++) for (int i = 0; i < a; i++)
{ {
cout<<array[i][j]; for (int j = 0; j < a; j++)
} {
cout<<endl; cout << array[i][j];
} }
cout<<"del the elements on the side:"<<endl; cout << endl;
for (int i=1;i<a-1;i++) }
{ cout << "del the elements on the side:" << endl;
for (int j=1;j<a-1;j++) for (int i = 1; i < a - 1; i++)
{ {
cout<<array[i][j]; for (int j = 1; j < a - 1; j++)
} {
cout<<endl; cout << array[i][j];
} }
int sum=0; cout << endl;
int i,j; }
for (i = a - 2 ,j = 1 ; i >= 1 ; i-- , j++) int sum = 0;
{ int i, j;
sum+=array[i][j]; for (i = a - 2, j = 1; i >= 1; i--, j++)
} {
cout<<"The sum of the diagonal:"<<sum<<endl; sum += array[i][j];
} }
return 0; cout << "The sum of the diagonal:" << sum << endl;
}
return 0;
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册