传送门:点击打开链接
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
The first line contains one integer number n (1 ≤ n ≤ 200) — length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Print one integer number — volume of text.
7 NonZERO
5
24 this is zero answer text
0
24 Harbour Space University
1
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
题意是给定一串字符串,求出每个单词中最多有几个大写字母。
代码实现:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
char map[205];
int i,n,ans,maxn;
while(cin>>n)
{
memset(map,'\0',sizeof(map));
for(i=0;i<=n;i++)
scanf("%c",&map[i]);
ans=0;maxn=0;
getchar();
for(i=0;i<=n;i++)
{
if(map[i]>='A'&&map[i]<='Z')
{
ans++;
}
if(map[i]==' ')
ans=0;
maxn=max(maxn,ans);
}
cout<<maxn<<endl;
}
return 0;
}
模拟。
代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
char map[105][105];
int main()
{
int m,n,i,j,k,ans1,ans2,ans3;
while(cin>>n>>m)
{
getchar();
for(i=0;i<n;i++)
{
scanf("%s",map[i]);
}
ans1=ans2=ans3=0;
for(i=0;i<n;i++)
{
char ch=map[i][0];
for(j=1;j<m;j++)
{
if(map[i][j]!=ch)
break;
}
if(map[i][0]=='R'&&j==m)
ans1++;
if(map[i][0]=='B'&&j==m)
ans2++;
if(map[i][0]=='G'&&j==m)
ans3++;
}
if(ans1==ans2&&ans2==ans3&&(ans1&&ans2&&ans3))
{
int flag=1;
if(n==2)
cout<<"YES"<<endl;
else
{
for(i=0;i<n;i+=ans1)
{
for(j=i+1;j<i+ans1;j++)
{
if(map[i][0]!=map[j][0])
flag=0;
}
}
if(flag)
{
cout<<"YES"<<endl;
}
}
if(flag)
continue;
}
ans1=ans2=ans3=0;
for(i=0;i<m;i++)
{
char ch=map[0][i];
for(j=1;j<n;j++)
{
if(map[j][i]!=ch)
break;
}
if(map[0][i]=='R'&&j==n)
ans1++;
if(map[0][i]=='B'&&j==n)
ans2++;
if(map[0][i]=='G'&&j==n)
ans3++;
}
if(ans1==ans2&&ans2==ans3&&(ans1&&ans2&&ans3))
{
int flag=1;
if(m==2)
cout<<"YES"<<endl;
else
{
for(i=0;i<m;i+=ans1)
for(j=i+1;j<i+ans1;j++)
if(map[0][i]!=map[0][j])
flag=0;
if(flag)
cout<<"YES"<<endl;
}
}
else
cout<<"NO"<<endl;
}
return 0;
}
模拟。
代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,x,y,maxn;
int map[105][2];
bool judge(int a,int b,int c,int d)
{
if(a<=c&&b<=d)
return true;
swap(a,b);
if(a<=c&&b<=d)
return true;
else
return false;
}
int main()
{
int i,j,k;
while(cin>>n>>x>>y)
{
for(i=0;i<n;i++)
cin>>map[i][0]>>map[i][1];
maxn=0;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
for(k=1;k<x;k++)
{
if(judge(map[i][0],map[i][1],k,y)&&judge(map[j][0],map[j][1],x-k,y))
break;
}
if(k<x)
maxn=max(maxn,map[i][0]*map[i][1]+map[j][0]*map[j][1]);
for(k=1;k<y;k++)
{
if(judge(map[i][0],map[i][1],x,k)&&judge(map[j][0],map[j][1],x,y-k))
break;
}
if(k<y)
maxn=max(maxn,map[i][0]*map[i][1]+map[j][0]*map[j][1]);
}
}
cout<<maxn<<endl;
}
return 0;
}