Advertisement
Guest User

Untitled

a guest
May 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. int main() {
  6.         int i=0;
  7.         int j=0;
  8.         int k=0;
  9.         int l=0;
  10.         int m=0;
  11.         char string1[200];
  12.         char string2[200];
  13.         printf("(1) Podaj dowolny ciag znakow:\n");
  14.         scanf("%s",&string1);
  15.         printf("(2) Podaj dowolny ciag znakow:\n");
  16.         scanf("%s",&string2);
  17.         for (i=0;i<200;i++) {
  18.                  if (isalpha(string1[i])!=0) {
  19.                                       k++;
  20.                                  }
  21.                 }
  22.         char tmp1[k];
  23.         for (i=0;i<200;i++) {
  24.                  if (isalpha(string1[i])!=0) {
  25.                                   tmp1[j]=string1[i];
  26.                                   j++;
  27.                                  }
  28.                 }
  29.         j=0;
  30.         for (i=0;i<200;i++) {
  31.                  if (isalpha(string2[i])!=0) {
  32.                                   l++;
  33.                                  }
  34.                 }
  35.         if (k!=l) {
  36.                printf("Wprowadzone ciagi znakow to nie anagramy!\n");
  37.                    return 0;
  38.                }
  39.         else {
  40.               char tmp2[l];
  41.               for (i=0;i<200;i++) {
  42.                            if (isalpha(string2[i])!=0) {
  43.                                         tmp2[j]=string2[i];
  44.                                         j++;
  45.                                        }
  46.                       }
  47.           for (i=0;i<k;i++) {
  48.                      if (isupper(tmp1[i])!=0) {
  49.                                    tolower(tmp1[i]);
  50.                                   }
  51.                     }
  52.           for (i=0;i<l;i++) {
  53.                      if (isupper(tmp2[i])!=0) {
  54.                                    tolower(tmp2[i]);
  55.                                   }
  56.                     }
  57.           for (i=0;i<k;i++) {
  58.                      for (j=0;j<l;j++) {
  59.                             if (tmp1[i]==tmp2[j]) {
  60.                                            m++;
  61.                                           }
  62.                                }
  63.                     }
  64.           if (m==i) {
  65.                      printf("Wprowadzone ciagi znakow to anagramy!\n");
  66.                 }
  67.           else {
  68.             printf("Wprowadzone ciagi znakow to nie anagramy!\n");
  69.                }
  70.           }
  71.         return 0;
  72.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement