Online 4, string and function;

 

 Basic Level

  1. Print length of a string

    • Input: "hello"

    • Output: 5

  2. Reverse a string

    • Input: "gojo"

    • Output: "ojog"

  3. Check Palindrome

    • Input: "madam"

    • Output: Yes

  4. Copy one string to another without using strcpy()

  5. Count vowels in a string


🟨 Intermediate Level

  1. Count frequency of each character

    • Input: "banana"

    • Output: a=3, b=1, n=2

  2. Check if two strings are anagrams

    • Input: "listen", "silent"

    • Output: Yes

  3. Convert all characters to uppercase

  4. Find number of words in a string

    • Input: "I love C programming"

    • Output: 4

  5. Remove all vowels from a string


🟦 Challenge Level

  1. Find the longest palindromic substring

  2. Find the first non-repeating character

  3. Count occurrences of a substring

  4. Sort characters in a string

  5. Implement custom strstr() function



#online rotationL
// /*Input:
// waterbottle
// erbottlewat*/
#include<stdio.h>
#include<string.h>
void rotation(char str1[], int n)
{
    int len= strlen(str1);
     
    char temp[100]; int k=0;
for(int i=0; i<n;i++)  //0,1
{
    temp[k++]= str1[i];
}
for(int i=0; i<len-n;i++) //0,1,2 |2,3,4
{
    str1[i]= str1[i+n];
}
int l=0;
for(int i=len-n; i<len; i++)
{
    str1[i]= temp[l++];  //3,4 0,1
}


}

int rotation_perfection(char str[], char str2[], int n)
{  int len = strlen(str);
    rotation(str,n);
    if(strcmp(str, str2)==0){return 1;}
    return 0;
}

 //abcde cdeab
int main()
{

   char str[100]; scanf("%s", str);
   char str2[100]; scanf("%s", str2);
char str3[100]; char str4[200];

  int n=strlen(str);
int result;

  for(int i=0; i<=n; i++)
  {result= rotation_perfection(str3, str4, i);
    if(result==1){result=1; break;}
    strcpy(str3, str);
strcpy(str4, str2);
  }
 
   printf("%d", result);
}

Comments

Popular posts from this blog

Phy 129 - WM, CT-03

Online 3 CSE 102; Array Resources.