|
[求助]
vs2017编写c语言程序时出现写入访问权限冲突
// ConsoleApplication5.cpp: 定义控制台应用程序的入口点。
// 《程序员的算法趣题》Q08 优秀的扫地机器人。
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
long long int mov(int, int*, int*);
//参数1:第j个位置
//参数2,3:横,纵坐标
long long int count;
int *p1, *p2;
int coordinate1[13];
//横坐标
int coordinate2[13];
//纵坐标
int main(void)
{
int j = 0;
count = 0;
coordinate1[j] = 0;
coordinate2[j] = 0;
//初始坐标为(0,0)
p1 = &coordinate1[0];
p2 = &coordinate2[0];
mov(j, p1, p2);
printf("%lld\n", count);
system("pause" ;
return 0;
}
long long int mov(int m, int *coordinate1, int *coordinate2)
{
int j;
j = m;
if (j == 13)
return 0;
int i;
for (i = 1; i < 5; i++)
{
switch (i)
{
case 1:
{
//前进:横坐标不变,纵坐标加1
*(coordinate2 + j + 1) = *(coordinate2 + j) + 1;
break;
}
case 2:
{
//后退:横坐标不变,纵坐标减1
*(coordinate2 + j + 1) = *(coordinate2 + j) - 1;
break;
}
case 3:
{
//左移:横坐标加1,纵坐标不变
*(coordinate1 + j + 1) = *(coordinate1 + j) + 1;
break;
}
case 4:
{
//右移:横坐标减1,纵坐标不变
*(coordinate1 + j + 1) = *(coordinate1 + j) - 1;
break;
}
default:
break;
}
j++;
int k;
for (k = j; k > 0; k--)
{
if (*(coordinate1 + j) == *(coordinate1 + k - 1) && *(coordinate2 + j) == *(coordinate2 + k - 1))
break;
}
if (k > 0)
{
continue;
}
m = j;
count = count + mov(m, p1, p2);
}
return count;
}
发自小木虫IOS客户端 |
|