| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12445 | Cola Exchange |
|
| 12448 | Hu_cheatsheet |
|
| 12511 | Pointer Sorting |
|
| 12560 | Permutation With Repetition |
|
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.
Input
Output
Sample Input Download
Sample Output Download
Tags
Discuss
Description
You will need to write a function to solve sorting problem.
ptr is a pointer, len is the length of ptr and is a complete square number, after we allocate it space according by the input.
After sorting ptr in non-descending order, you need to put it in a 2D array in row-major order, then return it in int** type.
Input
you don't need to worry it
Output
A 2D matrix
Remember to change line each row.
Sample Input Download
Sample Output Download
Partial Judge Code
12511.cPartial Judge Header
12511.hTags
Discuss
Description
Given a string of length n, print all permutation of the given string. and repetition of characters is allowed!.
There are few examples below:
Case1:
Input: A
output: A
Case2:
Input: AB
output: AA AB BA BB
Input
S
S: the input string ( 2 <= len(S)) < 7)
Note : the input string only contain alpha characters included upercase and lowercase.
Note : each element of input string is different.
Output
Ouput the permutation with repetition pattern (each output string followed by a newline characters)