| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12426 | Not Simple Unzip |
|
| 12429 | Going To Class |
|
| 12445 | Cola Exchange |
|
| 12448 | Hu_cheatsheet |
|
Description
After finishing the Simple ZIP program in the midterm practice, the next step is to write the unzip program to finish the whole zip/unzip project. It maybe an simple task for the safe/correct input, however your friend tell the bad news to you.In the reality, you can't always receive the safe/correct input, some input maybe the wrong format and make your program crash. Your program should handle the wrong input format.
The correct format of zip must be [integer][alpha][integer][alpha]....
[integer] is the integer > 0
[alpha] is the set of [a-z], [A-Z],['0','1',....'9']
[integer][alpha] is the basic zip pair unit
Take a correct format input for example : 3a3d4'1' should be unzip to aaaddd1111
Take a wrong format input for example : 5a5 should not be unzip and need to print out the error message "Can't unzip, the format is wrong!"
Note : If you are using visual studio, add #pragma warning(disable:4996) in the first line so that you can use scanf on your local machine.
Input
S_1
S_2
...
S_T
S_i :is the positive sequence ( 2 <= the size of the sequence <= 100)
T: is the number of testcase (2 <= T <= 10)
The input constraint:
1. The input symbol will only appear [a-z], [A-Z], [0-9],['0','1',....'9']
(it mean that the testcase will not include the sequence such like "%^@$@aabb'''11'z123'")
2. The integer number in the sequence is less than 100 and greater than -1
Testcase Hint:
Testcase 1 - 4 : safe input with the correct format
testcase 5 : safe input + wrong format input (wrong order of zip pair) ex: [alpha][inter], [integer][alpha][alpha][integer]...
Testcase 6 : safe input + wrong format input (mismatch pair) ex: [inter], [alpha], [inter][alpha][inter]...
testcase 7 : safe input + wrong format input (zero integer) ex: [0][alpha], [integer][alpha][0][alpha]...
Output
if the input sequence can be unzip then show the unzip result in the output, otherwise show the error messge "Can't unzip, the format is wrong!" in the output.(each line followed by a newline character)
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Your friend is a lazy person.
He has N classes on each Monday, where all of these classes happen in the same room.
Like everybody else, he likes some classes but also dislikes other classes.
Specifically, the i'th class gives A[i] happiness to him, where A[i] may be positive, negative, or zero.
It would be nice for him to attend classes so that the sum of happiness he get is maximum, but it is not an option for him to leave the class and then come back for another, because he is too lazy to move. In other words, he may only choose to attend classes that are conducted successively (one after another).
Again, lazy as your friend is, he wants you to find the maximum happiness he can achieve by optimally choosing the classes.
Input
N
A_1
A_2
...
A_N
(N is a positive integer not exceeding 5000, A_i is an integer where|A_i| <= 10000)
It is guaranteed that at least one of A_i is positive.
Output
The maximum happiness, followed by a newline character.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Source : Modified by Uva11150
One day, you see the following special offer by the convenience store:
"3 + E empty bottle of Choco Cola exchange for a new one."
E : After exchanging 10 new colas, E will increase by 1 (initial E = 0)
Now you decide to buy some (say N) bottles of cola from the store. You would like to know the most colas you can get from them.
Take N = 8 for example. At best, you will exchange 4 times and get 12 bottle in the end. (E = 0 since the number of exchange times less than 10)
Method 1 is the standard way: After finishing 8 bottles of cola, you have 8 empty bottles. Take 6 of them to the store and you get 2 new bottles of cola. Once you finish those 2 colas, you will have 4 empty bottles. You take 3 of them to the store for another 1 new cola. Finally, you have only 2 empty bottles in hand, so you cannot get any new cola. Hence, you have enjoyed 8 + 2 + 1 = 11 bottles of cola.
You can actually do better!
In Method 2, you can first borrow an empty bottle from your friend (?! Or the storekeeper??), then you can enjoy 8 + 3 + 1 = 12 bottles of cola! Of course, you need to return the remaining empty bottle to your friend(?! Or the storekeeper??).

In more complexity case, you need to handle the number of exchange times over 10. if the number of exchange times > 10, then you need to use 4 cola to exchange 1 cola, if the number of exchange times > 20, then you need to use 5 cola to exchange to 1 cola if the number of exchange times > 30, then you need to use 6 cola to exchange 1 cola ... and so on.
Note that: if you borrow bottles from your friend, you must return the empty bottles at the end of exchange
Note that: If you are using visual studio, add #pragma warning(disable:4996) in the first line so that you can use scanf on your local machine.
Input
Input consists of several lines, each containing an integer N (1 ≤ N ≤ 6000).
Output
For each case, your program should output the maximum number of bottles of cola you can enjoy. You may borrow empty bottles from others, but if you do that, make sure that you have enough bottles afterwards to return to them.(the output string follow by an newline character)
Note: Drinking too much cola is bad for your health, so... don’t try this at home!! :-)
Sample Input Download
Sample Output Download
Tags
Discuss
Description
printf() and scanf() format
printf("%d", n);
FORMAT ARGUMENT TYPE
%d, %i int decimal
%lld long long
%llu unsigned long long
%u unsigned int
%x unsigned int hexadecimal
%#x unsigned int hexadecimal with prefix 0x
%f double
%Lf long double
%c char to print a character
%s char * string (character array ended with '\0')
scanf("%d", &n);
FORMAT ARGUMENT TYPE
%d int * &n, store the input integer in n
%ld long *
%lld long long *
%u unsigned int *
%f float * read float
%lf double * read double
%Lf long double * read long double
%c char * read 3 characters %3c
%s char * read a string until whitespace
%n int * with %s, to get string length
char a[100]; int len;
scanf("%s%n", a, &len);
len will have the string length
Frequently used functions
#include <string.h>
char str[10];
scanf("%s", str);
to get the string length using strlen(str)
#include <ctype.h>
isspace(ch), islower(ch), isupper(ch), isdigit(ch)
isalpha(ch), toupper(ch), tolower(ch)
To create a 5-by-5 two-dimensional array, we need to write
int a[5][5];
It will be indexed as follows:
|
a[0][0] |
a[0][1] |
a[0][2] |
a[0][3] |
a[0][4] |
|
a[1][0] |
a[1][1] |
a[1][2] |
a[1][3] |
a[1][4] |
|
a[2][0] |
a[2][1] |
a[2][2] |
a[2][3] |
a[2][4] |
|
a[3][0] |
a[3][1] |
a[3][2] |
a[3][3] |
a[3][4] |
|
a[4][0] |
a[4][1] |
a[4][2] |
a[4][3] |
a[4][4] |
How to read the following data?
1 2 3 4 5 e
#include <stdio.h>
int main(void)
{
int x;
while (scanf("%d", &x) == 1) {
printf("x=%d\n", x);
}
return 0;
}
How to read the following data?
2
L 5 2
D 5 3
#include <stdio.h>
int main(void)
{
char ch;
int i, n, row, col;
scanf("%d", &n);
for (i=0; i<n; i++) {
while(getchar()!='\n');
scanf("%c%d%d", &ch, &row, &col);
}
return 0;
}
Using for loops to print a two-dimensional array
for(i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
printf("%5d", A[i][j]);
}
printf("\n");
}
logical and comparison operators operators:
! && || == != > < >= <=
arithmetic operators:
+ - * / %
bitwise operators:
& | ^ << >> ~
int strcmp(const char *lhs, const char *rhs);
int strcat(const char *lhs, const char *rhs);
int strcpy(const char *lhs, const char *rhs);
How to avoid common errors and how to debug for OJ
1. Put the arrays in the 'global' area. Set their size bigger than required. Avoid using variable-length arrays (e.g. int arr[n];). Keep the array size fix (e.g., int arr[1000];).
2. After writing the code for reading input data, you may print out the data to check if your code reads them correctly. Do not proceed to write subsequent code before you confirm that.
3. If your program crashes, usually it is caused by memory related errors. Check the ranges of for-loops to see if your code attempts to read or write the elements out of the arrays' boundary.
Note : If you are using visual studio, add #pragma warning(disable:4996) in the first line so that you can use scanf on your local machine.