Online 4, string and function;
Basic Level
-
Print length of a string
-
Input:
"hello" -
Output:
5
-
-
Reverse a string
-
Input:
"gojo" -
Output:
"ojog"
-
-
Check Palindrome
-
Input:
"madam" -
Output:
Yes
-
-
Copy one string to another without using
strcpy() -
Count vowels in a string
🟨 Intermediate Level
-
Count frequency of each character
-
Input:
"banana" -
Output:
a=3, b=1, n=2
-
-
Check if two strings are anagrams
-
Input:
"listen", "silent" -
Output:
Yes
-
-
Convert all characters to uppercase
-
Find number of words in a string
-
Input:
"I love C programming" -
Output:
4
-
-
Remove all vowels from a string
🟦 Challenge Level
-
Find the longest palindromic substring
-
Find the first non-repeating character
-
Count occurrences of a substring
-
Sort characters in a string
-
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
Post a Comment