Last active
November 10, 2016 19:06
-
-
Save rich-97/8dfe7b65fc4e9cd84dbbcccf6a53b41a to your computer and use it in GitHub Desktop.
the longest word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
#include "string.h" | |
int count = 0; | |
int max_len = 0; | |
int count_comp = 0; | |
int count_word = 0; | |
int count_index = 0; | |
int len = strlen(str); | |
int arr_nword[count_word]; | |
int arr_index[count_index]; | |
char str[] = "example example2 proof guide"; | |
int main () { | |
for (int i = 0; i <= len; i++) { | |
if (str[i] == ' ' || str[i] == '\0') { | |
arr_nword[count_word] = count; | |
count_word++; | |
count = 0; | |
} else count++; | |
} | |
for (int i = 0; i < count_word; i++) { | |
if (arr_nword[i] > max_len) | |
max_len = arr_nword[i]; | |
} | |
for (int i = 0; i <= len; i++) { | |
if (str[i] == ' ' || str[i] == '\0') { | |
if (count_comp == max_len) { | |
arr_index[count_index] = i; | |
count_index++; | |
} | |
count_comp = 0; | |
} else count_comp++; | |
} | |
for (int i = 0; i < count_index; i++) { | |
puts("the longest word is: "); | |
for (int j = (arr_index[i] - max_len); j < arr_index[i]; j++) | |
printf("%c", str[j]); | |
printf("\n"); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string = 'example example2 proof guide' | |
listStr = string.split() | |
listLength = [] | |
for i in listStr: | |
listLength.append(len(i)) | |
for i in listStr: | |
if (max(listLength) == len(i)): | |
print i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment