|
|
вернуться в форумplease check my code WA 3 #pragma comment(linker, "/STACK:16777216") #include <stdio.h> #include <string.h> #define size 20010 char str[size]; char arr[size]; int i=0; void recurse(int low,int high){ int mid; if(low>high) return; mid = (low+high)/2; arr[mid] = str[i++]; recurse(low,mid-1); recurse(mid+1,high); } int main(){ scanf(" %[^\n]s",str); recurse(0,strlen(str)-1); printf("%s\n",arr); return 0; } /*I simply used recursion and its working for all the test I know presently.Please tell me what is the problem in the code*/ Re: please check my code WA 3 input output Re: please check my code WA 3 Послано Xel 28 май 2014 19:25 the same def solve(str): l = len(str) if l<=2: return str mid = (1+l)//2 return solve(str[1:mid]) + str[0] + solve(str[mid:]) print solve(sys.stdin.readline().strip()) it's working for all the test I know, but get WA3 here Re: please check my code WA 3 Послано ura 3 фев 2019 13:55 Xel,отличное решение! Только вместо функции strip() нужна функция strip('\n'), иначе удаляются все концевые пробелы и этим самым нарушаются входные данные. Edited by author 03.02.2019 13:56 |
|
|