標題:
c462: apcs 交錯字串
[打印本頁]
作者:
ray
時間:
2020-7-4 10:09
標題:
c462: apcs 交錯字串
https://zerojudge.tw/ShowProblem?problemid=c462
作者:
ray
時間:
2020-7-4 10:47
#include <iostream>
#include <string>
using namespace std;
int main()
{
int k,max,len,type;
string str;
cin>>k>>str;
cout<<k<<":"<<str<<endl;
return 0;
}
複製代碼
作者:
ray
時間:
2020-7-4 10:48
https://openhome.cc/Gossip/CppGossip/string2.html
作者:
李知易
時間:
2020-7-4 12:08
本帖最後由 李知易 於 2020-7-11 11:36 編輯
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
int k,m,len,type,l,t;
string str;
cin>>k>>str;
m = len = l = 0;
for(int i = 0; i < str.length(); i++)
{
t = isupper(str[i]);
if(i == 0)
type = t;
if(type == t)
{
l++;
if(l > k)
len = k;
//if(l == k)
//len += k;
}
else
{
if(l < k)
len=0;
l=1;
//if(l == k)
//len+=k;
}
if(l == k)
len+=k;
m = max(len,m);
type = t;
}
cout<<m<<endl;
//system("pause");
return 0;
}
複製代碼
作者:
陳泓瑜
時間:
2020-7-4 12:08
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
int k, max=0, kl=0, type, ts, now=0;//ts=char type, type = switch, now -> max, kl -> k
string s;
cin>>k>>s;
if(s[0] >= 65 && s[0] <= 90)
{
type = 1;//uppercase: 1, lowercase: 0
ts = 1;
now++;
}
else
{
type = 0;//uppercase: 1, lowercase: 0
ts = 0;
now++;
}
for(int i = 1; i < s.length(); i++)
{
kl++;
if(s[i] >= 65 && s[i] <= 90)
ts = 1;
else
ts = 0;
if(type == ts)
now++;
if(kl == k)
{
kl = 0;
if(type = 1)
type = 0;
if(type = 0)
type = 1;
if(now >= max)
max = now;
now = 0;
}
}
cout<<max;
system("pause");
return 0;
}
複製代碼
作者:
陳泓瑜
時間:
2020-7-11 11:31
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
int k, max=0, kl=0, type, ts, now=0;//ts=char type, type = switch, now -> max, kl -> k
string s;
cin>>k>>s;
for(int i = 0; i < s.length(); i++)
{
ts = isupper(s[i]);
if(i == 0)
type = ts;
if(type == ts)
{
now++;
if(now > k)
kl = k;
if(now == k)
kl += k;
//cout<<s[i]<<"=="<<endl;
}
else
{
if(now < k)
kl = 0;
now=1;
if(now == k)
kl += k;
//cout<<s[i]<<"<>"<<endl;
}
if(kl > max)
max = kl;
type = ts;
//cout<<"kl="<<kl<<"now="<<now<<endl;
}
cout<<max;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2