Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- int is_l(char c){ //Se è una lettera ritorna il valore 1 altrimenti 0
- if (c <='z' && c >= 'a') return 1;
- if (c <='Z' && c >= 'A') return 1;
- return 0;
- }
- int is_c(char c){ //Se è una consonante ritorna 1 -- se è una vocale ritorna 0 -- nessuna dei due ritorna 2
- if(is_l(c)){
- char* check = "aeiouAEIOU";
- for(;*check;check++){
- if(c == *check) return 0;
- }
- return 1;
- }
- return 2;
- }
- int count_sil(char* stringa){ //Conta le sillabe (Conta i vocali)
- int i = 0;
- do{
- if(is_c(*stringa)==0) i++;
- stringa++;
- }while(*stringa);
- return i;
- }
- char* sillaba(char* stringa){
- int n = count_sil(stringa);
- char* finale;
- char* mem = (char*)calloc(n+1,sizeof(char));
- finale = mem;
- for(;*stringa;stringa++,mem++){
- if(is_c(*stringa)== 2){
- *mem = '-';
- }else{*mem = *stringa;}
- if(is_c(*stringa)==0 && is_c(*(stringa+1))!=2 ){
- if(is_c(*(stringa+1))==1){
- if(*(stringa+1)==*(stringa+2)){
- stringa++;
- mem++;
- *mem = *stringa;
- }
- }
- mem++;
- *mem = '-';
- }
- }
- *mem = '\0';
- return finale;
- }
- int frequenza(char* s1, char*s2){
- char* mem;
- mem = s1;
- int i = 0;
- for(;*s2;){
- if(*s1 == *s2){
- s1++;
- s2++;
- }else s2++;
- if (*s1 == '-' || *s1 == '\0'){
- i++;
- s1 = mem;
- }
- if (*s2 == '-'){
- s2++;
- }
- }
- return i;
- }
- char* salto(char* s, int i){
- int m = 0;
- if(m==i)return s;
- for(;*s;s++){
- if(*s=='-')m++;
- if(m==i)return (s+1);
- }
- return s;
- }
- char* copia(char* s){
- char* mem = (char*)malloc(sizeof(char)*4);
- int i;
- for(i=0;*s!='-';s++,i++){
- if(*s=='\0'){
- mem[i]='\0';
- return mem;
- }
- mem[i]= *s;
- }
- mem[i]='\0';
- return mem;
- }
- char* moda(char* s){
- int sillabe = count_sil(s);
- int i,n ;
- int max = 0;
- int risultato = 0;
- char* camp = sillaba(s);
- int freq[sillabe];
- for(i=0;i!=sillabe;i++){
- n = frequenza(salto(camp,i),camp);
- freq[i] = n;
- }
- freq[i]='\0';
- for(i=0;freq[i]!='\0';i++){
- if(freq[i]>max){
- max = freq[i];
- risultato = i;
- }
- }
- char* fine;
- fine = copia(salto(camp,risultato));
- return fine;
- }
- int main(){
- printf("%s\n", moda("mamma va va va va"));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement