CSES - E4590 2016 1 - Results
Submission details
Task:Reversals
Sender:EduardoVaca
Submission time:2016-09-17 15:14:02 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2--details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:18:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i", &word_length, &queries);
                                        ^
input/code.cpp:22:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", word);
                   ^
input/code.cpp:25:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i", &start, &end);
                               ^

Code

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void reverse_substring(char* start, char* end) {
	while(start < end) {
		char tmp = *start;
        *start++ = *end;
        *end-- = tmp;
	}
}

int main()
{
	int word_length, queries, i, start, end;
	char* word;

	scanf("%i %i", &word_length, &queries);

	word = (char*)malloc(word_length);

	scanf("%s", word);

	for(i = 0; i < queries; i++){
		scanf("%i %i", &start, &end);
		start--; end--;
		reverse_substring(word + start, word + end);		
	}
	printf("%s\n",word);

	free(word);
	
	return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
50 100
pplcmurzajsxlqqcrxewfhzqyihkzp...

correct output
fpuwlmatkzbhksppmjxpwurcvsdxcz...

user output
fpuwlmatkzbhksppmjxpwurcvsdxcz...

Test 2

Verdict:

input
500000 100000
slsmyuezdrenskmgkwxpcfzistssmu...

correct output
slsmyuezvdfzhssyoofpsnsagrrzri...

user output
(empty)