Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created June 28, 2011 18:10
Show Gist options
  • Save iporsut/1051766 to your computer and use it in GitHub Desktop.
Save iporsut/1051766 to your computer and use it in GitHub Desktop.
License Plate
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int check1(char *s) {
return strlen(s) == 1;
}
int check2(char *s) {
char *p = s;
while((*p == *s)) {
p++;
}
if (*p == '\0')
return 1;
return 0;
}
int check3(char *s) {
char *p = s;
if (strlen(s) >= 3) {
while( (*(p+1) != '\0') && (*(p+1) == ((*p)+1))) {
p++;
}
if (*(p+1) == '\0')
return 1;
}
return 0;
}
int check4(char *s) {
char *p,*q;
if (strlen(s) >= 3) {
p = s;
q = &(s[strlen(s)-1]);
while((p < q) && (*p == *q)) {
p++;
q--;
}
if (*p == *q)
return 1;
}
return 0;
}
int check5(char *s) {
int n;
n = atoi(s);
return (n % 100) == 0;
}
int check6(char *s) {
char *p,*q;
if (strlen(s) == 4) {
p = s;
q = s+2;
while((*q != '\0') && (*p == *q)) {
p++;
q++;
}
if( *q == '\0')
return 1;
}
return 0;
}
int main(int argc, char **argv) {
char in[5];
in[0] = ' ';
in[1] = '\0';
scanf("%s",in);
while(strcmp(in,"-1")) {
if (check1(in) || check2(in) || check3(in) || check4(in) || check5(in) || check6(in))
printf("%s\n",in);
scanf("%s",in);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment