Basic questions
1. Hello, world!
Title Description
This is the first problem for test. Since all we know the ASCII code, your job is simple: Input numbers and output corresponding messages.
Entry
The input will contain a list of positive integers separated by whitespaces(spaces, newlines, TABs). Please process to the end of file (EOF). The integers will be no less than 32.
Export
Output the corresponding message. Note there is NOT a newline character in the end of output.
Sample input
72 101 108 108 111 44
32 119 111 114 108 100 33
Sample Output
Hello, world!
c written language
#include<stdio.h>
int main() {
char c;
int a[100], i = 0;
while ((scanf("%d", &a[i])) != EOF) {//需要换行输入ctrl+z再回车
i++;
}
for (int j = 0; j < i; j++) {
printf("%c", a[j]);
}
return 0;
}
EOF, here are valid questions in a special training system inside the compiler is not valid
as the java sc.hasnext () the same. . emm
import java.util.Scanner;
/**
* @author 小喵钓鱼
* @date 2020-02-19 13:55
* @veision 1.10
*/
public class Pratice {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext())
{
int a = scanner.nextInt();
System.out.print((char)a);
}
}
}
Prime numbers seeking the sieve 2. Method N.
Title Description
Inner sieve number N of the prime requirements.
Entry
N
Export
0 ~ N prime number
Sample input
100
Sample Output
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
#include<stdio.h>
#include<math.h>
int su(int n);
int main(void) {
int n;
scanf("%d", &n);
for (int i = 2; i < n; i++)
{
if (su(i) != -1)
{
printf("%d\n", su(i));
}
}
}
// 素数就是 只被自己 和 1整除的数
int su(int n)
{
int i;
int k = (int)sqrt((double)n);
for (i = 2; i <= k; i++)
{
if (n % i == 0)
{
break;
}
}
if (i > k)
{
return n;
}
return -1;
}
3. Reverse character
#include <stdio.h>
#include <string.h>
int main(void)
{
char strinput[100];
scanf("%[^\n]", strinput); //除了换行符以外的字符全部接收
char stroutput[100];
int i = 0;
int j = 0;
int len = strlen(strinput);
//逆序拷贝
for (i = len - 1; i >= 0; i--)
{
stroutput[j++] = strinput[i];
}
stroutput[j] = '\0';
printf("%s\n", stroutput);
return 0;
}
java import java.util.Scanner; /** * @author 小喵钓鱼 * @date 2020-02-19 13:55 * @veision 1.10 */ public class Pratice { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); String str = scanner.nextLine(); for (int i = str.length() - 1; i >= 0; i--) { System.out.print(str.charAt(i)); } System.out.println(); } }
java
[Blue Bridge Cup] [2013 fourth Zhenti] Evaluate Formula
Time limit: 1Sec Memory Limit: 128MB submission: 1131 Resolution: 13
Title Description
Input n, m, k, value of the output of the following formula.
Wherein a combination of several C_n ^ m, m represents a selected number of programs consisting of a set of individuals in the set of n individual. The number of combinations is calculated as follows:
And the data size agreed
to 100% of the data, at no more than n-decimal 1000, i.e. 1≤n <10 ^ 1000,1≤k≤1000, while 0≤m≤n, k≤n.
Tip
999,101 is a prime number;
when n is the number of bits relatively long time, the answer is zero, but the evaluation will select some answers when the data is not zero in most cases;
Entry
The first row contains an integer n-input; second row contains an integer m, the third row contains an integer k.
Export
The calculated value of the above formula, because the answer is very large, please output value is divided by 999,101 in.
Sample input
3
1
3
Sample Output
162
// 第一次尝试
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n, m, k;
Scanner sc = new Scanner(System.in);
String blank;
n = sc.nextInt();
blank = sc.nextLine();
m = sc.nextInt();
blank = sc.nextLine();
k = sc.nextInt();
long sum = 0;
for (int i = 0; i <= n; i++)
{
sum += calcu(i, n) * calcu(m, n) * Math.pow(i, k);
}
System.out.println(sum % 999101);
}
public static long calcu(int m, int n)
{
long sum = 0;
sum = Jie(n) / (Jie(m) * Jie(n - m));
return sum;
}
public static long Jie(int n)
{
long sum = 1;
if(n == 0)
return 1;
for (int i = 1; i <= n; i++)
{
sum *= i;
}
return sum;
}
}
Logically there is no problem, that is, the number is too big, auto-zero, resulting in an error.
The number of [Blue Bridge Cup] [2013 fourth Zhenti] can not buy: Question 1427
Time limit: 1Sec Memory Limit: 128MB submission: 3255 Resolution: 1685
Title Description
Xiao Ming opened a candy store. He ingenuity: fruit sugar packets into a packet 4 and 7 two kinds of a packet. Candy unpacking can not sell.
When the children to buy sugar, he used to combine the two packaging. Of course, some combination of the number of candy is not out, for example, to buy 10 sugar.
You can use the computer test, in which case the package, can not buy the maximum number is 17. Any number greater than 17 can be used out of 4 and 7 in combination.
The title is required during two the number of packages are known, the combination can not find out the maximum number.
Entry
Two positive integer representing the number of teeth of each sugar packaging (not more than 1000)
Export
A positive integer representing the maximum number can not buy sugar
Sample input
4 7
Sample Output
17
import java.util.Scanner;
/**
* @author 小喵钓鱼
* @date 2020-02-19 16:46
* @veision 1.10
*/
public class A2013_4 {
public static void check(int m, int n)
{
// 最大组合数是不超过 m * n 的
if (m > n)
{
int temp = m;
m = n;
n = m;
}
for (int i = m * n; i > 0; i--)
{
if (!T(m, n , i))
{
System.out.println(i);
break;
}
}
}
public static boolean T(int m, int n, int i)
{
if (i % m == 0 || i % n == 0)
{
return true;
}
while (i >= m)
{
if (i % m == 0)
return true;
i -= n;
}
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int m, n; // 糖果数
Scanner sc = new Scanner(System.in);
m = sc.nextInt();
n = sc.nextInt();
check(m, n);
}
}
Here not the maximum number of combinations, should <product of two numbers and greater than or equal to the minimum of the number, and is the maximum number of returns False composition not pulled down, the first encountered can not be obtained from the product of two numbers