# | Problem | Pass Rate (passed user / total user) |
---|---|---|
12490 | Little Brick's Calculator |
|
13711 | Valid String |
|
14068 | Good Combination |
|
Description
Little Bricks(小磚頭) has a very brilliant calculator,
it can parse the numbers from a sentense and sum up all the numbers in the sentense.
One day, he broke the calculator,
but the calculator cannot be bought anymore,
so he ask you to make a new one for him.
ouo.
Hint:
This is a Partial Judge Problem:
0. You will be provided 2 files below: 'main.c', 'function.h'. You should only upload your 'solver' function inside your '.c' file.
1. The 'main.c' file contains input, output, and function call, the 'function.h' file contains the defination of 'solver' function, and your '.c' file should contain the implement of 'solver' function.
2. You can compile multiple files by command, ex: 'gcc main.c function.h your_code.c', or create a project in your IDE.
3. Remember to include 'function.h'.
main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include <stdio.h> #include "function.h" #define maxn 1000 char input[1000010]; int main() { int sum = 0; int a[maxn]; int *ptr[maxn]; for (int i = 0; i < maxn; i++) { a[i] = 0; ptr[i] = &a[i]; } scanf("%s", input); int n = solver(ptr, &sum, input); printf("%d", a[0]); for (int i = 1; i < n; i++) printf(" %d", a[i]); printf("\n%d\n", sum); return 0; } |
function.h
1 2 3 4 5 |
#ifndef FUNCTION_H #define FUNCTION_H int solver(int **ptr, int *sum, char *s); #endif |
For example, if the sentense is 'Now:12/31,23:59',
then you should parse the 4 numbers: 12, 31, 23, 59 out,
and calculate the sum of these numbers, which is 12+31+23+59=129
The numbers should be separate by a space, after a newline character, output the sum of numbers.
Note that your calculator should be able to handle negative number.
Input
Input contain only 1 line, a string S.
It is guarantee that:
0. 1<= |S| <= 10^6
1. Numbers in S will be in the range [-10^5, 10^5]
2. The ammount of number in S will be in the range [1, 1000]
Output
Output contains 2 lines.
The first line should output all numbers appear in the input string S, separate with a space character,
the next line should be the sum of numbers at the first line.
Sample Input Download
Sample Output Download
Partial Judge Code
12490.cPartial Judge Header
12490.hTags
Discuss
Description
You are given a string that contains dozens of brackets.
A valid string is a string such that every bracket in it is matched with another bracket.
For example, an empty string is a valid string.
Generally, a string is valid if one of the below's conditions is satisfied:
- The string is empty.
- The string starts with a left bracket and ends with a right bracket, and the string enclosed by these two brackets is valid.
- The string is two valid string's concatenation.
Your task is that, determine if the given string is valid, and you have to answer it for \(T\) times.
You may use the template below
#include<stdio.h> #include<stdlib.h> #include<string.h> #define MAXN 505 int record[MAXN][MAXN]; char s[MAXN]; int solve(int l, int r) { // return 1 if s[l, r] is valid, 0 otherwise. if (record[l][r] != -1) return record[l][r]; // If the substring is computed, return it immediately. int flag = 0; // store your answer for this state in flag. // [TODO] Implement your codes here. // Noticed that you only need to store the result in "flag". // End record[l][r] = flag; return flag; } int main () { int T; scanf("%d", &T); while (T--) { for (int i = 0;i < MAXN; ++i) for (int j = 0;j < MAXN; ++j) record[i][j] = -1; scanf("%s", s); int flag = solve(0, strlen(s)-1); printf(flag ? "Yes\n" : "No\n"); } return 0; }
Input
The first line contains a integer \(T\).
The next \(T\) lines, each contains string consists of brackets only.
- \(1 \le T \le 10\)
- \(1 \le |s| \le 500\)
Constraints
Output
Print \(T\) line, "Yes" if the string is valid, "No" otherwise.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given N numbers, you can choose M numbers out from them as one combination.
If one combination's sum equals K, we call it a 'good combination', please output all good combinations in lexicographical order.
Input
The first line is an integer T, the testcase numbers.
In the first line of each testcase has three numbers N M K.
The second line of each testcase are the given n numbers.
T <= 10, N <= 10, M <= 5, 1 <= K, ai <= 1e9.
Output
Please output all good combinations in lexicographical order.
Print a space after each number, and a '\n' after each line.