Last active
August 29, 2015 14:10
-
-
Save andrewgho/935ef44a1b75bf5d0152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gcc -Wall -Wno-char-subscripts -o is_steal is_steal.c */ | |
#include <stdio.h> | |
int is_steal(const char *base, const char *steal) { | |
char count[26] = {0}; | |
int bl, sl; | |
for(bl = sl = 0; base[bl]; bl++) { | |
if(count[base[bl]] > 0) { | |
count[base[bl]]--; | |
} else { | |
for(; steal[sl] && steal[sl] != base[bl]; sl++, count[steal[sl]]++); | |
if(!steal[sl]) return 0; | |
} | |
} | |
for(; sl <= bl && steal[sl]; sl++); | |
return sl > bl; | |
} | |
int main(int argc, const char **argv) { | |
if(is_steal(argv[1], argv[2])) { | |
puts("true"); | |
return 0; | |
} else { | |
puts("false"); | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment