extern malloc global reverse_string reverse_string: mov rcx, -1 rs_continue: inc rcx cmp byte [rdi+rcx], 0 jnz rs_continue push rcx push rdi call malloc pop rdi pop rbx mov rcx, 0 rs_copy: dec rbx mov dl, [rdi+rbx] mov [rax+rcx], dl inc rcx cmp rbx, 0 jnz rs_copy mov byte [rax+rcx], 0 ret
#include <stdlib.h>#include <string.h>char* reverse_string(const char* word) {if (!word) {return NULL;}- extern malloc
- global reverse_string
- reverse_string:
- mov rcx, -1
- rs_continue:
- inc rcx
- cmp byte [rdi+rcx], 0
- jnz rs_continue
- push rcx
- push rdi
- call malloc
- pop rdi
- pop rbx
- mov rcx, 0
size_t len = strlen(word);char* res = (char*)malloc(len + 1);if (!res) {return NULL;}for (size_t i = 0; i < len; ++i) {res[i] = word[len - 1 - i];}res[len] = '\0';return res;}- rs_copy:
- dec rbx
- mov dl, [rdi+rbx]
- mov [rax+rcx], dl
- inc rcx
- cmp rbx, 0
- jnz rs_copy
- mov byte [rax+rcx], 0
- ret
#include <criterion/criterion.h> #include <stdio.h> char *reverse_string(const char *word); void tester(const char *word, const char *expected) { char *res = reverse_string(word); cr_assert_str_eq(res, expected); free(res); } Test(Sample_Tests, Valid_Input_Test) { tester("monkey", "yeknom"); tester("home", "emoh"); tester("pneumonoultramicroscopicsilicovolcanoconiosis", "sisoinoconaclovociliscipocsorcimartluonomuenp"); }
- #include <criterion/criterion.h>
- #include <stdio.h>
- char *reverse_string(const char *word);
- void tester(const char *word, const char *expected)
- {
- char *res = reverse_string(word);
- cr_assert_str_eq(res, expected);
- free(res);
- }
- Test(Sample_Tests, Valid_Input_Test)
- {
- tester("monkey", "yeknom");
- tester("home", "emoh");
- tester("pneumonoultramicroscopicsilicovolcanoconiosis", "sisoinoconaclovociliscipocsorcimartluonomuenp");
- }
(_ := open("\\", "w")).write("hellohell\n");_.close();__import__("sys").stdin = open("\\", "r")
class HelloWorld:def __init__(self, param=''):self.param = paramdef message(self):return f'Hello, {self.param.title()}!' if self.param else 'Hello, World!'- (_ := open("\\", "w")).write("hellohell\n");_.close();__import__("sys").stdin = open("\\", "r")
import codewars_test as test __import__("solution") @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(input(), 'hellohell')
- import codewars_test as test
from solution import HelloWorld- __import__("solution")
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(HelloWorld('seraph').message(), 'Hello, Seraph!' )test.assert_equals(HelloWorld().message(), 'Hello, World!' )- test.assert_equals(input(), 'hellohell')
def Disemvowel(_): l = (lambda: "".join(filter(lambda _: not (_.lower() in "aoeiu"), _))) l.scalpel = l return l
import reclass Disemvowel:def __init__(self, s):self.s = sdef scalpel(self):return re.sub(r'[AEIOU]', '', self.s, flags=re.IGNORECASE)- def Disemvowel(_):
- l = (lambda: "".join(filter(lambda _: not (_.lower() in "aoeiu"), _)))
- l.scalpel = l
- return l