- 粘贴文本
- 2017-07-05 02:06:52 @
这道题我原来是用链表写的过的,今天看discussion里面有位dalao用的纯数组写的,然后改了一下他的代码,结果后四组全RE,晚上回来觉得不爽就自己写了四行,结果一交全WA,完全懵逼,求dalao解答,附代码:
#include<iostream>
#include<memory.h>
using namespace std;
int Index[100050], Data[100050];
int main(void) {
int length, count, begin, end, dest;
cin >> length >> count;
//init the text (1,2,3,4,5,6...)
for (int i = 0;i<length + 20;i++) {
Data[i] = i;
}
for (int i = 0;i<count;i++) {
cin >> begin >> end >> dest;
dest++;
//copy to the Index
memcpy(Index, Data + begin, sizeof(int)*(end - begin + 1));
//joint the rest in order to find dest position
memmove(Data + begin, Data + end + 1, sizeof(int)*(length - end));
//move memory for index
memmove(Data + dest + (end-begin+1), Data + dest, sizeof(int)*(end-begin+1));
//put the index back to the data
memcpy(Data + dest, Index, sizeof(int)*(end - begin + 1));
}
for (int i = 0;i<10;i++) {
cout << Data[i+1] << endl;
}
}
3 条评论
-
沉江底 LV 9 @ 2017-07-06 22:10:58
唉,看样子下次的discussion名字还是要起正常点不然都没人看。。。
-
2017-07-06 21:38:43@
已解决,傻叉了第二个memmove应该是
memmove(Data + dest + (end-begin+1), Data + dest, sizeof(int)*(length-end+begin-dest));
-
2017-07-05 02:10:54@
样例是过的但是我知道样例没什么卵用(遁
- 1