Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
string match2
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Title of this code //g++ 4.8.2 #include <iostream> bool match(const std::string& str1, const std::string& str2, int err, unsigned i = 0, unsigned j = 0) { if (i >= str1.length() || j >= str2.length() || err < 0) return false; if (str1[i] != str2[j]) --err; if (i == str1.length() - 1 && j == str2.length() - 1 && err >= 0) return true; return match(str1, str2, err, i + 1, j + 1) || match(str1, str2, err, i + 1, j) || match(str1, str2, err, i, j + 1); } bool match(const std::string& str1, const std::string& str2, int err, unsigned i = 0, unsigned j = 0) { if (i >= str1.length() || j >= str2.length() || err < 0) return false; while (str1[i] == str2[j] && i < str1.length()-1 && j < str2.length()-1) { ++i; ++j; } if (i < str1.length() && j < str2.length() && str1[i] != str2[j]) --err; if (i == str1.length() - 1 && j == str2.length() - 1 && err >= 0) return true; return match(str1, str2, err, i + 1, j + 1) || match(str1, str2, err, i + 1, j) || match(str1, str2, err, i, j + 1); } int main() { std::cout << match("abba", "abba", 1); }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.43 sec, absolute running time: 0.04 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0.48 sec
edit mode
|
history
|
discussion
1