8.19华为笔试第一题只A了20%

第一题从30分开始写,结果一直出错,还是很多地方不扎实
~vector<vector>可以直接push({i,j}) 不需要vector<pair<i,j>>
~括号一定要英文
~想要cnt每次循环保存上一次的值,main(){cnt=0,fill(cnt)} void(&cnt)
调用函数时直接代cnt,定义函数时用&cnt
~输出[[][]]
printf默认会[],有逗号
可以cout<<"["<<a[0][i]<<","<<"]"

凉了,心痛
#include
#include
#include
using namespace std;

bool Isrightnum(int num)
{
num = num % 100;

int a = num % 10;
int b = num / 10;


if (a == 7 && b % 2 == 1) return true;
else return false;

}

void fillnum(vector<vector> &matrix, int &start_x, int &start_y, int &end_x, int &end_y ,int &cnt , vector<vector> &ans)
{

for (int j = start_y; j <= end_y; j++)
{
    
    matrix[start_x][j] = cnt;
    if (Isrightnum(cnt))
    {
        ans.push_back({ start_x, j });
    }
    cnt++;
}//输出matrix[start_x][start_y] ---- matrix[start_x][end_y]

for (int i = start_x + 1; i < end_x; i++)
{
    matrix[i][end_y] = cnt;
    if (Isrightnum(cnt))
    {
        ans.push_back({ i, end_y });
    }
    cnt++;
}//输出matrix[start_x+1][end_y] ---- matrix[end_x-1][end_y]
for (int j = end_y; j >= start_y; j--)
{
    matrix[end_x][j] = cnt;
    if (Isrightnum(cnt))
    {
        ans.push_back({ end_x, j });
    }
    cnt++;
}//输出matrix[m-1][n-1] ---- matrix[m-1][start_y]
for (int i = end_x-1; i >= start_x + 1; i--)
{
    matrix[i][start_y] = cnt;
    if (Isrightnum(cnt))
    {
        ans.push_back({ i,start_y });
    }
    cnt++;
}//输出matrix[m-2][start_y] ---- matrix[start_x+1][start_y]

}

int main()
{
vector<vector> ans;
int m;
cin >> m;
int n;
cin >> n;

if (m >= 10 && m <= 1000 && n >= 10 && m <= 1000)
{
    vector<vector<int>> matrix(m, vector<int>(n, 0));

    int start_x = 0;
    int start_y = 0;
    int end_x = m - 1;
    int end_y = n - 1;
    int cnt = 1;
    int a = 0;



    while (end_x >= 0 && end_y >= 0 && start_x <= m && start_y <= n)
    {
        fillnum(matrix, start_x, start_y, end_x, end_y, cnt, ans);

        start_x++;
        start_y++;
        end_x--;
        end_y--;
    }
    cout << "[";
    for (int i = 0; i < ans.size(); i++)
    {
        if (i == ans.size() - 1)
        {
            cout << "[" << ans[i][0] << "," << ans[i][1] << "]";
        }
        else
        {
            cout << "[" << ans[i][0] << "," << ans[i][1] << "]" << ",";
        }
    }
    cout << "]";

}

else
{
    return 0;
}
    


system("pause");
return 0;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值