Blue Bridge Cup-basic training

Source: Internet
Author: User

BASIC-1 leap year judgment Problem Description

Given a year, it is not a leap year to judge.

This is a leap year when one of the following conditions is met:

1. The year is a multiple of 4 rather than a multiple of 100;

2. The year is a multiple of 400.

None of the other years is a leap year.

Input FormatThe input contains an integer y that represents the current year.output FormatOutputs a row, or output Yes if the given year is a leap, otherwise outputs No.

Description: When the question specifies that you want to output a string as a result (for example, yes or no, you need to strictly follow the case given in the question, and the case will not score.)

Sample Input2013Sample OutputNoSample Input2016Sample OutputYes Data size and convention 1990 <= y <= 2050.
import Java.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner sc=NewScanner (System.inch); inty=Sc.nextint (); if(y>=1990&&y<=2050) {            if(y%4==0&&y% -!=0) {System. out. println ("Yes"); }Else if(y% -==0) {System. out. println ("Yes"); }Else{System. out. println ("No"); }        }    }}
BASIC-201-character string Problem Description

For a 01-string length of 5 bits, each bit can be 0 or 1, a total of 32 possible. The first few of them are:

00000

00001

00010

00011

00100

Please output these 32 kinds of 01 strings in order from small to large.

Input FormatThis question is not entered.output FormatOutput 32 rows, in order from small to large, each line is a length of 5 01 strings.Sample Output00000
00001
00010
00011
< The following sections omit >method One:
 Public classMain { Public Static voidMain (string[] args) {intN=5;  for(inti = 0; I < Math.pow (2, N); i++)         {//Format (string format, Object ... args) returns a formatted string using the specified format string and parameters. //"%0" +n+ "D" is missing with 0 padding//tobinarystring (Long i) returns the string representation of a long parameter as a binary unsigned integer. String S=string.format ("%0" +n+ "D", Long.parselong (long.tobinarystring (i)));        System.out.println (s); }    }}

If it is a String s=string.format ("%d", Long.parselong (long.tobinarystring (i)));

So the result is

0
1
10
11
100
101< the following section omitted >

If it is a String s=string.format ("%5d", Long.parselong (long.tobinarystring (i)));

So the result is

0
1
10
11
100< the following section omitted >

Method Two:

 Public class Main {    publicstaticvoid  main (string[] args) {        for ( int i = 0; I < 32; i++) {            System.out.print (i%32/16);            System.out.print (i%16/8);            System.out.print (i%8/4);            System.out.print (i%4/2);            System.out.print (i%2);            System.out.println ();     }}}

Method Three:

 Public classMain2 { Public Static voidMain (string[] args) {inta,b,c,d,e;  for(a=0;a<2;++a) for(b=0;b<2;++b) for(c=0;c<2;++c) for(d=0;d<2;++d) for(e=0;e<2;++e) {System.out.print (a);                            System.out.print (b);                            System.out.print (c);                            System.out.print (d);                            System.out.print (e);                        System.out.println (); }    }}

Method Four: Violence law

#include <stdio.h>intMain () {printf ("00000\n"); printf ("00001\n"); printf ("00010\n"); printf ("00011\n"); printf ("00100\n"); printf ("00101\n"); printf ("00110\n"); printf ("00111\n"); printf ("01000\n"); printf ("01001\n"); printf ("01010\n"); printf ("01011\n"); printf ("01100\n"); printf ("01101\n"); printf ("01110\n"); printf ("01111\n"); printf ("10000\n"); printf ("10001\n"); printf ("10010\n"); printf ("10011\n"); printf ("10100\n"); printf ("10101\n"); printf ("10110\n"); printf ("10111\n"); printf ("11000\n"); printf ("11001\n"); printf ("11010\n"); printf ("11011\n"); printf ("11100\n"); printf ("11101\n"); printf ("11110\n"); printf ("11111\n"); return 0; }

Method Five:

#include <iostream>#include<string>using namespacestd;intMain () {inti,j; stringStr="00000";  for(i=0;i< +;++i) {cout<<str<<Endl; str[4]+=1;  for(j=4; j>=0;--j) {if(str[j]=='2') {str[j-1]+=1; STR[J]='0'; }        }    }    return 0;}

BASIC-3 Letter Graphic

Problem Description

Using letters to make some beautiful graphics, here's an example:

ABCDEFG

Babcdef

Cbabcde

Dcbabcd

Edcbabc

This is a 5 row 7-column graph, find out the pattern of the graph, and output an n-row m-column graph.

Input FormatEnter a row that contains two integers n and m, representing the number of columns of the number of rows of the graph you want to output.output FormatOutput n lines, each m characters, for your graphics.Sample Input5 7Sample OutputABCDEFG
Babcdef
Cbabcde
Dcbabcd
EDCBABC data size and conventions 1 <= N, M <= 26.

Blue Bridge Cup-basic training

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.