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.
import java.util.Scanner;
/**
*
* 作者:张宇翔
* 创建日期:2017年8月3日 下午10:54:33
* 描述:永远的ACM
*/
public class Main {
private static final int Max=(int) (1e6+10);
private static int n;
private static String s;
public static void main(String[] args) {
InitData();
GetAns();
}
private static void InitData() {
Scanner cin=new Scanner(System.in);
n=cin.nextInt();
cin.nextLine();
s=cin.nextLine();
};
private static void GetAns(){
String []split=s.split(" ");
int ans=Integer.MIN_VALUE;
for(int i=0;i='A'&&split[i].charAt(j)<='Z'){
cnt++;
}
}
ans=Math.max(ans, cnt);
// System.out.println(split[i]);
}
System.out.println(ans);
}
}
The flag of Berland is such rectangular field n × m that satisfies following conditions:
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
YES
4 3
BRG
BRG
BRG
BRG
YES
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
NO
4 4
RRRR
RRRR
BBBB
GGGG
NO
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
import java.util.Scanner;
/**
*
* 作者:张宇翔
* 创建日期:2017年8月3日 下午10:54:33
* 描述:永远的ACM
*/
public class Main {
private static final int Max=(int) (1e3+10);
private static int n,m;
private static String s[];
public static void main(String[] args) {
InitData();
GetAns();
}
private static void InitData() {
Scanner cin=new Scanner(System.in);
s=new String[Max];
n=cin.nextInt();
m=cin.nextInt();
for(int i=0;i
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
2 2 2
1 2
2 1
4
4 10 9
2 3
1 1
5 10
9 11
56
3 10 10
6 6
7 7
20 5
0
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
import java.util.Scanner;
/**
*
* 作者:张宇翔
* 创建日期:2017年8月3日 下午10:54:33
* 描述:永远的ACM
*/
public class Main {
private static final int Max=(int) (1e3+10);
private static int n,a,b;
private static int []x;
private static int []y;
public static void main(String[] args) {
InitData();
GetAns();
}
private static void InitData() {
Scanner cin=new Scanner(System.in);
x=new int[Max];
y=new int[Max];
n=cin.nextInt();
a=cin.nextInt();
b=cin.nextInt();
for(int i=0;i
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Print maximal roundness of product of the chosen subset of length k.
3 2
50 4 20
3
5 3
15 16 3 25 9
3
3 3
9 77 13
0
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1,[50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
/**
*
* 作者:张宇翔
* 创建日期:2017年8月3日 下午10:54:33
* 描述:永远的ACM
*/
public class Main {
private static final int Max=(int) (1e3+10);
private static int n,k;
private static ArrayList list2;
private static ArrayList list5;
private static ArrayList list25;
public static void main(String[] args) {
InitData();
GetAns();
}
private static void InitData() {
Scanner cin=new Scanner(System.in);
list2=new ArrayList<>();
list5=new ArrayList<>();
list25=new ArrayList<>();
n=cin.nextInt();
k=cin.nextInt();
long a;
for(int i=0;i() {
@Override
public int compare(Node25 o1, Node25 o2) {
return Math.min(o1.con2, o1.con5)-Math.min(o2.con2, o2.con5);
}
});
Collections.sort(list2,new Comparator() {
@Override
public int compare(Node2 o1, Node2 o2) {
return o1.con2-o2.con2;
}
});
Collections.sort(list5,new Comparator() {
@Override
public int compare(Node5 o1, Node5 o2) {
return o1.con5-o2.con5;
}
});
int cnt=0;
int ANS2=0,ANS5=0;
int len2=list2.size()-1;
int len5=list5.size()-1;
int len25=list25.size()-1;
while(cnt=0||len5>=0||len25>=0)){
int ans1=-1,ans2=-1,ans3=-1;
if(len25>=0){
ans1=Math.min(list25.get(len25).con2, list25.get(len25).con5);
}
if(len2>=0){
ans2=list2.get(len2).con2;
}
if(len5>=0){
ans3=list5.get(len5).con5;
}
if(cnt==k-1){
// if(ans1!=-1){
// ANS2+=list25.get(len25).con2;
// ANS5+=list25.get(len25).con5;
// }else{
// if(ans2!=-1&&ans3!=-1){
// if(Math.min(ANS2+ans2, ANS5)>=Math.min(ANS2, ANS5+ans3)){
// ANS2+=ans2;
// }else{
// ANS5+=ans3;
// }
// }else if(ans2!=-1&&ans3==-1){
// ANS2+=ans2;
// }else{
// ANS5+=ans3;
// }
// }
if(ans1!=-1&&ans2!=-1&&ans3!=-1){//!!!
int k1=Math.min(ANS2+list25.get(len25).con2, ANS5+list25.get(len25).con5);
int k2=Math.min(ANS2+ans2, ANS5);
int k3=Math.min(ANS2, ANS5+ans3);
int k=Math.max(k1, Math.max(k2, k3));
if(k==k1){
ANS2+=list25.get(len25).con2;
ANS5+=list25.get(len25).con5;
}else if(k==k2){
ANS2+=ans2;
}else{
ANS5+=ans3;
}
}else if(ans1!=-1&&ans2!=-1&&ans3==-1){//!!=
int k1=Math.min(ANS2+list25.get(len25).con2, ANS5+list25.get(len25).con5);
int k2=Math.min(ANS2+ans2, ANS5);
int k=Math.max(k1, k2);
if(k==k1){
ANS2+=list25.get(len25).con2;
ANS5+=list25.get(len25).con5;
}else{
ANS2+=ans2;
}
}else if(ans1!=-1&&ans2==-1&&ans3!=-1){//!=!
int k1=Math.min(ANS2+list25.get(len25).con2, ANS5+list25.get(len25).con5);
int k2=Math.min(ANS2, ANS5+ans3);
int k=Math.max(k1, k2);
if(k==k1){
ANS2+=list25.get(len25).con2;
ANS5+=list25.get(len25).con5;
}else{
ANS5+=ans3;
}
}else if(ans1!=-1&&ans2==-1&&ans3==-1){//!==
ANS2+=list25.get(len25).con2;
ANS5+=list25.get(len25).con5;
}else if(ans1==-1&&ans2!=-1&&ans3!=-1){//=!!
int k2=Math.min(ANS2+ans2, ANS5);
int k3=Math.min(ANS2, ANS5+ans3);
int k=Math.max(k2, k3);
if(k==k2){
ANS2+=ans2;
}else{
ANS5+=ans3;
}
}else if(ans1==-1&&ans2!=-1&&ans3==-1){//=!=
ANS2+=ans2;
}else if(ans1==-1&&ans2==-1&&ans3!=-1){//==!
ANS5+=ans3;
}else if(ans1==-1&&ans2==-1&&ans3==-1){//===
continue;
}
break;
}
if(ans1>=Math.min(ans2, ans3)&&ans1!=-1){
ANS2+=list25.get(len25).con2;
ANS5+=list25.get(len25).con5;
len25--;
cnt++;
}else{
if(ans2!=-1&&ans3!=-1){
ANS2+=ans2;
ANS5+=ans3;
}else if(ans2!=-1&&ans3==-1){
ANS2+=ans2;
}else{
ANS5+=ans3;
}
len2--;
len5--;
cnt+=2;
}
}
// System.out.println(ANS2+" "+ANS5);
System.out.println(Math.min(ANS2, ANS5));
}
private static void Get(long x){
int ans2=0,ans5=0;
while(x%2==0){
ans2++;
x/=2;
}
while(x%5==0){
ans5++;
x/=5;
}
if(ans2!=0&&ans5!=0){
Node25 node25=new Node25(ans2, ans5);
list25.add(node25);
}else if(ans2!=0&&ans5==0){
Node2 node2=new Node2(ans2);
list2.add(node2);
}else{
Node5 node5=new Node5(ans5);
list5.add(node5);
}
}
static class Node2{
int con2;
public Node2(int con2) {
this.con2 = con2;
}
}
static class Node5{
int con5;
public Node5(int con5) {
this.con5 = con5;
}
}
static class Node25{
int con2;
int con5;
public Node25(int con2, int con5) {
this.con2 = con2;
this.con5 = con5;
}
}
}