鱼C论坛

 找回密码
 立即注册
查看: 3240|回复: 2

c++剩下最后四道题做不来了,求各位帮助

[复制链接]
发表于 2018-12-26 16:22:03 | 显示全部楼层 |阅读模式
30鱼币
希望大家能帮我一下,最好注释详细一点谢谢大家了

4.png
3.png
2.png
1.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-26 20:36:14 | 显示全部楼层
好高深,求教中
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-27 12:15:02 | 显示全部楼层
只会第四题
  1. #include<iostream>
  2. #define MAX 50
  3. using namespace std;

  4. void Show(int N, int a[MAX][MAX])
  5. {
  6.         for (int i = 0; i < N; i++)
  7.         {
  8.                 for (int j = 0; j < N; j++)
  9.                 {
  10.                         cout << a[i][j] << "\t";
  11.                 }
  12.                 cout << endl;
  13.         }
  14.         cout << endl;
  15. }

  16. void Huanfang(int N, int a[MAX][MAX])
  17. {
  18.         //初始化矩阵;
  19.         for (int i = 0; i < N; i++)
  20.         {
  21.                 for (int j = 0; j < N; j++)
  22.                 {
  23.                         a[i][j] = 0;
  24.                 }
  25.         }
  26.         int x = 0,y=N/2;
  27.         int number = 1;
  28.         while (number <= N*N)
  29.         {
  30.                 if (a[x][y] != 0)
  31.                 {
  32.                         x = (x + 1) % N;
  33.                         x = (x + 1) % N;
  34.                         y = (y - 1 + N) % N;
  35.                 }
  36.                 else
  37.                 {
  38.                         a[x][y] = number;
  39.                         number++;
  40.                         x = (x - 1+N) % N;
  41.                         y = (y+1) % N;
  42.                 }
  43.         }
  44. }

  45. //int Check(int n, int a[MAX][MAX])
  46. //{
  47. //        for (int i = 0; i<n; i++)
  48. //        {
  49. //                int s = 0;
  50. //                for (int j = 0; j < n; j++)
  51. //                {
  52. //                        s += a[i][j];
  53. //                }
  54. //                cout << s << endl;
  55. //        }
  56. //        for (int j = 0; j<n; j++)
  57. //        {
  58. //                int s = 0;
  59. //                for (int i = 0; i < n; i++)
  60. //                {
  61. //                        s += a[i][j];
  62. //                }
  63. //                cout << s << endl;
  64. //        }
  65. //        int        s = 0;
  66. //        for (int i = 0; i < n;i++)
  67. //        {
  68. //                s += a[i][i];
  69. //        }
  70. //        cout << s << endl;
  71. //        s = 0;
  72. //        for (int i = 0; i < n; i++)
  73. //        {
  74. //                s += a[n - 1 - i][i];
  75. //        }
  76. //        cout << s << endl;
  77. //        return 0;
  78. //}
  79. int main()
  80. {       
  81.         int a[MAX][MAX];
  82.         int n;
  83.         cin >> n;
  84.         while (n != 0)
  85.         {       
  86.                 if (n % 2 == 1)
  87.                 {
  88.                         Huanfang(n, a);
  89.                         Show(n, a);
  90.                         //Check(n, a);
  91.                 }
  92.                 else
  93.                 {
  94.                         cout << "ERROR!" << endl << endl;
  95.                 }
  96.                
  97.                 cin >> n;
  98.         }
  99.        
  100.         system("pause");
  101.         return 0;
  102. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-14 15:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表