A. Text Volume
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Input
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.
Output
Print one integer number — volume of text.
Examples
Input
7
NonZERO
Output
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
Note
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.
题目大意:给出一个整数n,然后给出一句子,句子有n个字母,问这个句子中,单词里最多有多少个大写的英文字母?
这个题目是比较的简单,刚开始的时候是想着用Java解决的,但是在吃掉那个换行符的时候不会,对于一个Java菜鸟的我来说很心酸,找了很多博客就是没有找到自己想要的答案
c++代码
#include <bits/stdc++.h>
using namespace std;
const int N = 212;
int main(){
int n;
scanf("%d", &n);
getchar();
char s[N];
gets(s);
int sum = 0, out = 0;
for (int i = 0; i < strlen(s); i++){
if (s[i] == ' '){
sum = max(sum, out);
out = 0;
}
else if ('A' <= s[i] && s[i] <= 'Z'){
out++;
}
else{
sum = max(sum, out);
}
}
if (out > 0) sum = max(sum, out);
printf("%d\n", sum);
return 0;
}
Java代码
有点颓,改了很久才改好的,后面还错了一发,忘了把中间输出的语句注释了
import java.util.*;
public class Main{
public static void main(String arges[]){
Scanner in = new Scanner(System.in);
String n = in.nextLine();
//byte d;
//d = in.nextByte();
String input = in.nextLine();
//System.out.println(input);
char c[] = input.toCharArray();
int put = 0;
int sum = 0;
for (int i = 0; i < c.length; i++){
if (c[i] == ' '){
sum = max(sum, put);
put = 0;
}
else if ('A' <= c[i] && c[i] <= 'Z'){
put++;
}
else{
sum = max(sum, put);
}
}
if (put > 0) sum = max(sum, put);
System.out.println(sum);
in.close();
// return ;
}
public static int max(int a, int b){
return a > b ? a : b;
}
}
本文介绍了一个简单的编程任务,即计算给定文本中每个单词的最大数量的大写字母。提供了C++和Java两种语言的实现代码。
186

被折叠的 条评论
为什么被折叠?



