| [25ae32e] | 1 | #include <ctype.h> |
|---|
| 2 | #include <stdio.h> |
|---|
| 3 | |
|---|
| 4 | inline |
|---|
| 5 | bool inline_matchattr(const char* a, const char* b) |
|---|
| 6 | { |
|---|
| 7 | const char *p, *q; // pomocnicze wskazniki |
|---|
| 8 | while(*a && *b) |
|---|
| 9 | { |
|---|
| 10 | p=a; q=b; |
|---|
| 11 | while(isupper(*p) && isupper(*q)) // rowny prefiks |
|---|
| 12 | if(*p==*q) ++p, ++q; |
|---|
| 13 | else if(*p<*q) // a jest mniejszy |
|---|
| 14 | { |
|---|
| 15 | // przesywamy a do nastepnego atr |
|---|
| 16 | a=p; |
|---|
| 17 | while(isupper(*a)) ++a; while(islower(*a)) ++a; |
|---|
| 18 | goto end; |
|---|
| 19 | } |
|---|
| 20 | else |
|---|
| 21 | { |
|---|
| 22 | // przesuwamy b do nastepnego atr |
|---|
| 23 | b=q; |
|---|
| 24 | while(isupper(*b)) ++b; while(islower(*b)) ++b; |
|---|
| 25 | goto end; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | if(islower(*p) && islower(*q)) // rowne atrybuty |
|---|
| 29 | { |
|---|
| 30 | a=p; b=q; // przesuwamy wskaznik, sprawdzamy wartosci |
|---|
| 31 | while(*a != *b) |
|---|
| 32 | { |
|---|
| 33 | if(*a > *b && !islower(*++b)) return false; |
|---|
| 34 | if(*a < *b && !islower(*++a)) return false; |
|---|
| 35 | } |
|---|
| 36 | // znaleziono rowna wartosc, przesywamy a i b do nast atr |
|---|
| 37 | while(isupper(*a)) ++a; while(islower(*a)) ++a; |
|---|
| 38 | while(isupper(*b)) ++b; while(islower(*b)) ++b; |
|---|
| 39 | goto end; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | if(islower(*p)) // a jest krotszy, czyli mniejszy |
|---|
| 43 | { // przesuwamy a do nastepnego atrybutu |
|---|
| 44 | a=p; |
|---|
| 45 | while(islower(*a)) ++a; |
|---|
| 46 | goto end; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | if(islower(*q)) // b jest krotszy, czyli mniejszy |
|---|
| 50 | { // przesuwamy b do nastepnego atrybutu |
|---|
| 51 | b=q; |
|---|
| 52 | while(islower(*b)) ++b; |
|---|
| 53 | goto end; |
|---|
| 54 | } |
|---|
| 55 | end: ; |
|---|
| 56 | } |
|---|
| 57 | return true; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | bool matchattr(const char* a, const char* b) |
|---|
| 62 | { |
|---|
| 63 | return inline_matchattr(a,b); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | bool matchdescr(const char* a, const char* b) |
|---|
| 67 | { |
|---|
| 68 | while(isupper(*a) && isupper(*b) && *a==*b) ++a, ++b; |
|---|
| 69 | if(*a=='\0') |
|---|
| 70 | if(*b=='\0' || *b=='/') return true; |
|---|
| 71 | else return false; |
|---|
| 72 | |
|---|
| 73 | if(*a=='/') |
|---|
| 74 | if(*b=='\0') return true; |
|---|
| 75 | else if(*b=='/') return inline_matchattr(++a, ++b); |
|---|
| 76 | |
|---|
| 77 | return false; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | int main() |
|---|
| 82 | { |
|---|
| 83 | char a[100], b[100]; |
|---|
| 84 | while(scanf("%s %s", a, b)==2) |
|---|
| 85 | printf("%s & %s = %d\n", a, b, matchdescr(a,b)); |
|---|
| 86 | } |
|---|