Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int daLiJeCifra(char str);
- void najkraciPodstringCifri(char str1[], char str2[]);
- void najduziPodstringCifri(char str1[], char str2[]);
- int main(void) {
- printf("Najkraci najduzi podstring od cifri:\n");
- char str1[50] = "svdb638sh22h1 ";
- char str2[50], str3[50];
- najkraciPodstringCifri(str1, str2);
- printf("Najkraci podstring cifri \"%s\" od stringa \"%s\"\n\n", str2, str1);
- najduziPodstringCifri(str1, str3);
- printf("Najduzi podstring cifri \"%s\" od stringa \"%s\"\n\n", str3, str1);
- return 0;
- }
- int daLiJeCifra(char str) {
- if (str >= '0' && str <= '9') {
- return 1;
- }
- return 0;
- }
- void najkraciPodstringCifri(char str1[], char str2[]) {
- int i = 0, j = 0, max = 0, duzina, index, temp = 0;
- while (str1[i] != '\0') {
- j = i;
- if (daLiJeCifra(str1[i])) {
- while (daLiJeCifra(str1[j]) && str1[j] != '\0') {
- j++;
- }
- }
- duzina = j - i;
- if (temp == 1) {
- if (duzina < max && duzina != 0) {
- index = i;
- max = duzina;
- }
- }
- else if (temp == 0 && duzina > 0) {
- index = i;
- max = duzina;
- temp++;
- }
- i = j + 1;
- }
- for (int i = index; i < max + index; i++)
- {
- str2[i - index] = str1[i];
- }
- str2[max] = '\0';
- }
- void najduziPodstringCifri(char str1[], char str2[]) {
- int i = 0, j, max, index, duzina, temp = 0;
- while (str1[i] != '\0') {
- j = i;
- if (daLiJeCifra(str1[i])) {
- while (daLiJeCifra(str1[j]) && str1[j] != '\0') {
- j++;
- }
- }
- duzina = j - i;
- if (temp) {
- if (duzina != 0 && max < duzina) {
- max = duzina;
- index = i;
- }
- }
- else if (temp == 0 && duzina != 0) {
- max = duzina;
- index = i;
- temp++;
- }
- i = j + 1;
- }
- for (int i = index; i < max + index; i++)
- {
- str2[i - index] = str1[i];
- }
- str2[max] = '\0';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement