tyrion

nodoppie.c

Feb 11th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 26
  3.  
  4. int indexof(char c) {
  5.     return c - 'a';
  6. }
  7.  
  8.  
  9. // ritorna 1 se non ci sono doppie 0 altrimenti.
  10. char nodoppie(char stringa[]) {
  11.     int occorrenze[N] = { 0 };
  12.     int i;
  13.  
  14.     for (char *c = stringa; *c != '\0'; ++c) {
  15.         i = indexof(*c);
  16.         if (occorrenze[i] == 1) return 0;
  17.         else occorrenze[i]++;
  18.     }
  19.     return 1;
  20. }
  21.  
  22. int main() {
  23.     char test1[] = "cisonodoppie";
  24.     char test2[] = "quino";
  25.     printf("%d %d\n", nodoppie(test1), nodoppie(test2));
  26. }
Advertisement
Add Comment
Please, Sign In to add comment