คือโค้ดผมเป็นดังนี้ครับ
Code (C++)
#include <stdio.h>
#include <stdlib.h>
long seq[500005], direction = 1;
long firstindex = 0, n, m;
long output[500005];
long count = 0;
long modulo (long x, long y) //return x mod y
{
return (x + y) % y;
}
void opera()
{
long x, y, tmp;
scanf("%ld %ld", &x, &y);
tmp = seq[modulo(firstindex + (x - 1) * direction, n)];
seq[modulo(firstindex + (x - 1) * direction, n)] = seq[modulo(firstindex + (y - 1) * direction, n)];
seq[modulo(firstindex + (y - 1) * direction, n)] = tmp;
}
void operb()
{
long x, k;
scanf("%ld %ld", &x, &k);
seq[modulo(firstindex + (x - 1) * direction, n)] = k;
}
void operq()
{
long x;
scanf("%ld", &x);
output[count] = seq[modulo(firstindex + (x - 1) * direction, n)];
count++;
//printf("real index is %ld\n", (firstindex + (x - 1) * direction) % n);
}
void operc()
{
long x;
scanf("%ld", &x);
firstindex = x - firstindex - 1;
direction = (-1)*direction;
}
int main()
{
//declaration
long i;
char choice, free;
//input and process
scanf("%ld %ld", &n, &m);
//printf("%ld %ld\n", n, m);
for (i = 0; i < n; i++)
scanf("%ld", &seq[i]);
scanf("%c", &free);
for (i = 0; i < m; i++)
{
scanf("%c", &choice);
switch (choice)
{
case 'a' : opera();
break;
case 'b' : operb();
break;
case 'c' : operc();
break;
case 'q' : operq();
}
scanf("%c", &free);
//printf("activate round %ld\n", i);
}
for (i = 0; i < count; i++)
printf("%ld\n", output[i]);
//system("pause");
return 0;
}
ส่งแล้วได้ X หลายตัวเลย
ทั้งที่ทดสอบแล้วว่ามันทำงานได้ ถ้าผิดควรจะเป็น - มากกว่าที่จะเป็น X
ที่แปลกก็คือ ลอง copy โค้ดโจทย์ข้อนี้ของคนอื่น (มีอยู่ในกระทู้อื่น) ไปทดสอบในเครื่องผม ปรากฏว่ารันไม่ได้ ขึ้น error report (แต่คอมไพล์ผ่าน) แต่เมื่อส่งขึ้นเว็บแล้วกลับไม่ติด X สักตัว
(มีแค่ P กับ T)
ช่วยไขข้อปัญหานี้ให้กระจ่างทีครับ
โดย Agent Shiney เมื่อ 11 Mar 2553 23:21:46