Nhập vào một xau ki tự in ra dãy số xuất hiện dài nhất trong xâu đó? vd: lan123quynh34567 -->4 34567

2 câu trả lời

For i:=1 to lenght(s) do 

   Begin

      Val(s[i],n,kt);

      If kt=0 then

         Begin

          insert(s2,1,n); 

           Inc(dem);

         End;      

   End;

Write(dem,’   ‘,s2);

//nhap kb tự làm

Code c:

 

#include<stdio.h>

#include<string.h>

#define max 100

int main()

{

            char s[max];

            printf("Nhap chuoi: ");

            gets(s);

            printf("Chuoi da nhap la: ");

            puts(s);

                        int a[max],m=0;

            int n=strlen(s)-1;

            int i,j;

            for(i=0;i<=n;i++)

            {

                        int d=0;

                        for(j=0;j<=n;j++)

                        {

                                    j=0;

                                    while(j<=n)

                                    {

                                                if(s[i]==s[j])

                                                {

                                                            d++;

                                                }

                                                j++;

                                    }

                        }

                        a[m]=d;

                        m++;

            }

            int k;

            int maxx=a[0];

            int maxi=0;

            for(k=0;k<m;k++)

            {

                        if(a[k]>maxx)

                        {

                                    maxx=a[k];

                                    maxi=k+1;

                        }

            }

            int l,g;

            char s1[1];

            for(l=0;l<m;l++)

            {

                        for(g=0;g<n;g++)

                        {

                                    if(maxi==g)

                                    {

                                                s1[0]=s[g-1];

                                    }

                        }

            }

                                    printf("So %s vi tri thu %d  xuat hien nhieu nhat, %d lan.",s1,maxi,maxx);

}

Câu hỏi trong lớp Xem thêm