#31454: 求救阿


P2006950413 (說不得)

學校 : 不指定學校
編號 : 185048
來源 : [111.251.70.70]
最後登入時間 :
2024-03-26 19:41:18
c462. apcs 交錯字串 (Alternating Strings) -- apcs | From: [61.228.7.119] | 發表日期 : 2022-08-02 09:33

#include<bits/stdc++.h>//請問我的程式錯在哪裡
using namespace std;

int main()
{
    int k;
    
    
    while(cin>>k)
    {
        string a;
        cin>>a;
        int count=0,big=0;
        int hl;
        bool b=0;
        int tmp;
        
        hl=a.length();
        
        
        for(int i=0;i<hl-k+1;i++)
        {
            b=0;
            if(isupper(a[i]))
            {
                b=1;
            }
            
            for(int j=i;j<i+k;j++)
            {
                if(isupper(a[j])!=b)
                {    
                    break;
                }
                
                if(j==(i+k-1))
                {
                    count=k;
                    
                    
                    b=1-b;
                    tmp=j;
                    j++;
                    
                    while(isupper(a[j])==b)
                    {
            
                        if((j-tmp)%k==0)
                        {
                            b=1-b;
                            count+=k;
                            
                        }
                        
                        
                        if(j>=hl-1)
                            break;


                        j++;
                    }
                    
                    
    
                }
                
                if(big<count)
                        big=count;
                        
                count=0;
            }
        }
        
        cout<<big<<"\n";
    }

    return 0;
}

 
ZeroJudge Forum