Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.5 kB
2
Indexable
Never
    import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] length=new int[n];
        int[] operations=new int[n];
        String[] string=new String[n];
        int count=0;
        for(int i=0;i<n;i++)
        {
            int l=sc.nextInt();
            int o=sc.nextInt();
            String s=sc.next();
            length[i]=l;
            operations[i]=o;
            string[i]=s;
        }
        for(int i=0;i<n;i++)
        {
            int o=operations[i];
            String s=string[i];
            for(int k=0;k<s.length();k++)
            {
                char t=s.charAt(k);
                for(int j=k+1;j<s.length();j++)
                {
                    if(Character.isUpperCase(t))
                    {
                        if(s.charAt(j)== Character.toLowerCase(t))
                        {
                            s=s.substring(0, j) +s.substring(j+1);
                            count++;
                            break;
                        }
                        else if(s.charAt(j)== Character.toUpperCase(t))
                        {
                            if(o>0)
                            {
                                o--;
                                count++;
                                s=s.substring(0, j) +s.substring(j+1);
                                break;

                            }
                        }
                    }
                    else if(Character.isLowerCase(t))
                    {
                        if(s.charAt(j)== Character.toUpperCase(t))
                        {
                            s=s.substring(0, j) +s.substring(j+1);
                            count++;
                            break;
                        }
                        else if(s.charAt(j)== Character.toLowerCase(t))
                        {
                            if(o>0)
                            {
                                s=s.substring(0, j) +s.substring(j+1);
                                o--;
                                count++;
                                break;

                            }
                        }
                    }
                }
            }
            System.out.println(count);
            count=0;
        }
        sc.close();;
    }
    }




Leave a Comment