ecfr 26 A. Text Volume

本文介绍了一个简单的编程任务,即计算给定文本中每个单词的最大数量的大写字母。提供了C++和Java两种语言的实现代码。

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;
    }
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值