Skip to content

Instantly share code, notes, and snippets.

@gdemir
Created March 22, 2011 22:18
Show Gist options
  • Select an option

  • Save gdemir/882209 to your computer and use it in GitHub Desktop.

Select an option

Save gdemir/882209 to your computer and use it in GitHub Desktop.
En uzun kelimeyi bulan program
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXLINE 1000
// Liste için bir struct yapısı
typedef struct list {
char *item;
struct list *next;
}LIST;
LIST *head_list = NULL;
// white space mi ?
int ws(char c) {
return c == ' ' || c == '\t' || c == '\n';
}
// liste için bir split fonksiyonu
LIST *split(char *s) {
int i, j = 0, state = 0;
LIST *part;
char *store = malloc(sizeof(LIST));
for (i = 0; i < strlen(s); i++) {
if (!ws(s[i])) {
store[j++] = s[i];
state = 1;
}
if((ws(s[i]) && state) || s[i + 1] == '\0') {
store[j] = '\0';
part = malloc(sizeof(LIST));
part->item = strdup(store);
part->next = head_list;
head_list = part;
free(store);
store = malloc(sizeof(LIST));
j = 0;
state = 0;
}
}
free(store);
return part;
}
// listede max'ı bul.
void max(LIST *new) {
char *result = "" ;
for (new = head_list; new; new = new->next)
if (strlen(new->item) > strlen(result))
result = strdup(new->item);
printf("kelime : %s, uzunluk : %ld", result, strlen(result));
}
// listeyi boşalt.
void empty(LIST *new) {
for (new = head_list; new; free(new), new = new->next)
;/* void */
}
int main() {
LIST *new_list = split("hani kuslar agaclar binbir renkli cicekler");
max(new_list);
empty(new_list);
return 0;
}
#!/usr/bin/python
#-*- coding: utf-8 -*-
def en_uzun_kelime(sectence):
store = dict()
words = str.split(sectence)
for word in words: store[len(word)] = word
key = max(store.keys())
print store[key], ":", key
# DIKKAT! Türkçe karakterler 2 byte yer kaplıyor.
en_uzun_kelime("hani kuşlar ağaçlar binbir renkli çicekler")
#!/usr/bin/ruby
#-*- coding:utf-8 -*-
def en_uzun_kelime sectence
word = sectence.split(" ").reduce("") {|result, word| result = word if result.length < word.length; result}
puts "#{word} #{word.length}"
end
# DIKKAT! Türkçe karakterler 2 byte yer kaplıyor.
en_uzun_kelime("hani kuşlar ağaçlar binbir renkli çicekler")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment