# 蓝桥杯训练题 (一)

### 基础题

#### 1. Hello, world!

This is the first problem for test. Since all we know the ASCII code, your job is simple: Input numbers and output corresponding messages.

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.

Output the corresponding message. Note there is NOT a newline character in the end of output.

72 101 108 108 111 44
32 119 111 114 108 100 33

Hello, world!

c语言编写

#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，这里在专门的题训练系统里面才有效，编译器中无效

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);
}
}
}


#### 2.用筛法求之N内的素数。

N

0～N的素数

100

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.字符逆序

#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;
}

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

#### [蓝桥杯][2013年第四届真题]公式求值

999101是一个质数；

3
1
3

162
java
// 第一次尝试
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;
}
}


#### 问题 1427: [蓝桥杯][2013年第四届真题]买不到的数目

4 7

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);
}
}


posted @ 2020-02-19 17:39  小喵钓鱼  阅读(76)  评论(1编辑  收藏