Wednesday, October 30, 2013

codechef HS08TEST - ATM c++ solution

my codechef HS08TEST - ATM c++ solution

codechef HS08TEST - ATM problem: http://www.codechef.com/problems/HS08TEST/

ATM

All submissions for this problem are available.

Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if Xis a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US.
Calculate Pooja's account balance after an attempted transaction.

Input

Positive integer 0 < X <= 2000 - the amount of cash which Pooja wishes to withdraw.
Nonnegative number 0<= Y <= 2000 with two digits of precision - Pooja's initial account balance.

Output

Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance.

Example - Successful Transaction

Input:
30 120.00

Output:
89.50

Example - Incorrect Withdrawal Amount (not multiple of 5)

Input:
42 120.00

Output:
120.00

Example - Insufficient Funds

Input:
300 120.00

Output:
120.00


here is my c++ solution to codechef HS08TEST - ATM problem. http://ideone.com/hF0KPo
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
// your code goes here
int a;
float b;
cin>>a>>b;
if(a%5==0&&a<=b-0.5) b=b-a-0.50;
cout<<fixed<<setprecision(2)<<b;
return 0;
}


codechef TEST - Life, the Universe, and Everything solution

codechef TEST - Life, the Universe, and Everything c++ solution

codechef TEST - Life, the Universe, and Everything problem: http://www.codechef.com/problems/TEST

Life, the Universe, and Everything

All submissions for this problem are available.

For help on this problem, please check out our tutorial Input and Output (I/O)
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.

Example

Input:
1
2
88
42
99

Output:
1
2
88



here is my c++ solution to codechef TEST - Life, the Universe, and Everything: http://ideone.com/fFjAxP
#include <iostream>
using namespace std;

int main() {
 // your code goes here
 int a;
 while(1) {
  cin>>a;
  if(a==42) break;
  else cout<<a<<endl;}
 return 0;
}

Sunday, October 20, 2013

uri OJ 1009 Salary with Bonus problem c++ solution

uri OJ 1009 Salary with Bonus problem: http://www.urionlinejudge.com.br/judge/en/problems/view/1009

URI Online Judge | 1009

Salary with Bonus

Timelimit: 1
You have to calculate the final salary for your employee, based on value sold by him. So you have to read his name, his fixed salary and the value sold by him. Your functionary wins 15% over all products sold. Write the final (total) salary of this functionary, rounded to two decimal places.
- Don’t forget to print end line after the result otherwise you will get “Presentation Error”.
- Don’t forget the blank spaces.

Input

The input file contains an string (employee first name), the salary of this employee and the total value sold by him.

Output

Print the total salary of the employee, according to the given example.
Sample InputSample Output
JOAO
500.00
1230.30
TOTAL = R$ 684.54
my c++ solution to uri OJ 1009 Salary with Bonus problem:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main() {
    // your code goes here
    double a, b;
    string c;
    cin>>c>>a>>b;
    cout<<"TOTAL = R$ "<<fixed<<setprecision(2)<<a+(b*15)/100<<endl;
    return 0;
}

uri OJ 1008 Salary problem c++ solution

uri OJ 1008 problem link: http://www.urionlinejudge.com.br/judge/en/problems/view/1008

uri OJ 1008 Salary problem: URI Online Judge | 1008

Salary

Timelimit: 1
Write a program that reads the number of an employee, the number of hours that he worked in a month and the amount he received per hour. Print the employee number and the salary that he will receive at end of the month, rounded to two decimal places.
- Don’t forget to print end line after the result otherwise you will get “Presentation Error”.
- Don’t forget the space before and after the equal signal and after the U$.

Input

The input file contains 2 integer numbers and 1 floating-point number, respectively the number, hours worked and the among received by an hour worked.

Output

Print the number and the salary of the employee, according to the given example, with a blank space before and after the equal signal.
Sample InputSample Output
25
100
5.50
NUMBER = 25
SALARY = U$ 550.00
and here is my c++ solution to uri OJ 1008 Salary problem:

#include <iostream>
#include <iomanip>
using namespace std;

int main() {
// your code goes here
float a, b, c;
cin>>a>>b>>c;
cout<<"NUMBER = "<<a<<endl<<fixed<<setprecision(2)<<"SALARY = U$ "<<b*c<<endl;
return 0;
}

uri OJ 1007 c++ solution

uri OJ 1007 problem link: http://www.urionlinejudge.com.br/judge/en/problems/view/1007

uri OJ 1007 problem. URI Online Judge | 1007

Difference

Timelimit: 1
Make a simple program that reads four variables named A, B, C and D. Calculate and print the difference of the product of A and B with the product of C and D (A * B - C * D).

Input

The input file contains 4 integer numbers.

Output

Print DIFERENCA (DIFFERENCE in portuguese) according to the following example, with a blank space before and after the equal signal.
Sample InputSample Output
5
6
7
8
DIFERENCA = -26
my c++ solution to uri OJ 1007 problem: http://ideone.com/rRC7Gx
#include <iostream>
using namespace std;

int main() {
// your code goes here
int A, B, C, D, DIFERENCA;
cin>>A>>B>>C>>D;
cout<<"DIFERENCA = "<<((A*B)-(C*D))<<endl;
return 0;
}

Saturday, October 19, 2013

my c++ solution to codeforces 1A Theatre Square problem

here is codeforces 1A Theatre Square problem link: http://codeforces.com/problemset/problem/1/A

here is codeforces 1A Theatre Square problem:
A. Theatre Square
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input
The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).
Output
Write the needed number of flagstones.
Sample test(s)
input
6 6 4
output
4

and here is my c++ solution link to codeforces 1A Theatre Square problem: http://ideone.com/c9QKZU



here is my c++ solution to codeforces 1A Theatre Square problem:


#include <iostream>
using namespace std;

int main() {
long long n, m, a;
cin>>n>>m>>a;
cout<<(((n+a-1)/a)*((m+a-1)/a));
return 0;
}




light OJ 1006 solution in c++

light OJ 1006 problem link: http://lightoj.com/volume_showproblem.php?problem=1006

light OJ 1006 problem: 1006 - Hex-a-bonacci
Time Limit: 0.5 second(s)Memory Limit: 32 MB
Given a code (not optimized), and necessary inputs, you have to find the output of the code for the inputs. The code is as follows:
int a, b, c, d, e, f;
int fn( int n ) {
    if( n == 0 ) return a;
    if( n == 1 ) return b;
    if( n == 2 ) return c;
    if( n == 3 ) return d;
    if( n == 4 ) return e;
    if( n == 5 ) return f;
    return( fn(n-1) + fn(n-2) + fn(n-3) + fn(n-4) + fn(n-5) + fn(n-6) );
}
int main() {
    int n, caseno = 0, cases;
    scanf("%d", &cases);
    while( cases-- ) {
        scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
        printf("Case %d: %d\n", ++caseno, fn(n) % 10000007);
    }
    return 0;
}

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains seven integers, a, b, c, d, e, f and n. All integers will be non-negative and 0 ≤ n ≤ 10000 and the each of the others will be fit into a 32-bit integer.

Output

For each case, print the output of the given code. The given code may have integer overflow problem in the compiler, so be careful.

Sample Input

Output for Sample Input

5
0 1 2 3 4 5 20
3 2 1 5 0 1 9
4 12 9 4 5 6 15
9 8 7 6 5 4 3
3 4 3 2 54 5 4
Case 1: 216339
Case 2: 79
Case 3: 16636
Case 4: 6
Case 5: 54


my solution in c++ to light OJ 1006 Hex-a-bonacci problem link: http://ideone.com/pYjAzX

my solution in c++ to light OJ 1006 Hex-a-bonacci problem: 
#include <iostream>
#include <cstring>
#include <cstdio>

#define maxn 10003
using namespace std;
long long fn[maxn];
int main() {
// your code goes here
int n, cases, caseno=0, i;
cin >> cases;
while (cases--) {
fn[6]=0;
for (i=0;i<6;i++) {
scanf("%lld",&fn[i]); fn[i]=fn[i]%10000007;
fn[6]=(fn[6]+fn[i])%10000007;
}
cin >> n;
for (i=7;i<=n;i++) {
fn[i]=(fn[i-6]+fn[i-5]+fn[i-4]+fn[i-3]+fn[i-2]+fn[i-1])%10000007;
}
cout<<"Case "<<++caseno<<": "<<fn[n]<<endl;
}
return 0;
}


and here is my friend Quan's solution in c: http://ideone.com/HQvLu3
#include <cstdio>
#include <cstring>
#define maxn 10003
using namespace std;
long long fn[maxn];
int main() {
    int n, caseno = 0, cases,i;
    scanf("%d", &cases);
    while( cases-- ) {
    fn[6]=0;
    for (i=0;i<6;i++){
    scanf("%lld",&fn[i]); fn[i] = fn[i] % 10000007;
    fn[6]=(fn[6]+fn[i]) % 10000007;
    }
    scanf("%d",&n);
    for (i=7;i<=n;i++) fn[i]=(fn[i-1]+fn[i-2]+fn[i-3]+fn[i-4]+fn[i-5]+fn[i-6])% 10000007;
    //fn[i]=((2*fn[i-1]*10000007)-fn[i-7]) % 10000007;
        printf("Case %d: %lld\n", ++caseno, fn[n] );
    }
    return 0;
}

Thursday, October 17, 2013

light OJ "1001 - opposite task" problem solution in c++

focus on not different output value, but instead that all output should be lesser than 10
focus on that thing

here is problem link: http://lightoj.com/volume_showproblem.php?problem=1001

here is problem: 1001 - Opposite Task
Time Limit: 0.5 second(s)Memory Limit: 32 MB
This problem gives you a flavor the concept of special judge. That means the judge is smart enough to verify your code even though it may print different results. In this problem you are asked to find the opposite task of the previous problem.
To be specific, I have two computers where I stored my problems. Now I know the total number of problems is n. And there are no duplicate problems and there can be at most 10 problems in each computer. You have to find the number of problems in each of the computers.
Since there can be multiple solutions. Any valid solution will do.

Input

Input starts with an integer T (≤ 25), denoting the number of test cases.
Each case starts with a line containing an integer n (0 ≤ n ≤ 20) denoting the total number of problems.

Output

For each case, print the number of problems stored in each computer in a single line. A single space should separate the non-negative integers.

Sample Input

Output for Sample Input

3
10
7
7
0 10
0 7
1 6


here is my solution link: http://ideone.com/1U2Kke

and here is my c++ solution to light OJ "1001 - opposite task" problem:
#include <iostream>
using namespace std;

int main() {
// your code goes here
int T, n;
cin >> T;
for (int i = 1; i <= T; i++) {
cin >> n;
if (n > 10) {
cout << n - 10 << " " << n - (n - 10) << "\n";
}
else {
cout << 0 << " " << n << "\n";
}
}
return 0;
}

Wednesday, October 16, 2013

light OJ.com "1000 - Greetings from LightOJ" solution in c++

OMG, it is so amazing to be able to solve OJ problems by yourself. i wish good luck to you also guys.

here is the question link: http://lightoj.com/volume_showproblem.php?problem=1000

here is problem: 1000 - Greetings from LightOJ
Time Limit: 0.5 second(s)Memory Limit: 32 MB
You are one of the most talented programmers and like to solve challenging problems. And my task is to make your life a bit complex by setting some easy looking hard brain storming problems such that you can sharpen your skills by practicing here. So, I wrote a code which shows a message like the following line:
Greetings from LightOJ
After that the code will select a random problem for you from my problems database based on your previously solved problems, your skills and your weaknesses. But while I was coding for implementing this great idea, I found that, all of my problems are scattered in 2 computers. So, I have to merge them before running my code.
Now you are given the number of problems in each of the computers, you have to find the total number of problems. You can safely assume that no problem is stored in multiple computers. So, all the problems are distinct.

Input

Input starts with an integer T (≤ 125), denoting the number of test cases.
Each case starts with a line containing two integers a and ba denotes the number of problems in the first computer and b denotes the number of problems in the second computer. You can safely assume that a and b will be non-negative and not greater than 10.

Output

For each case, print the case number and the total number of problems. See the samples for exact formatting.

Sample Input

Output for Sample Input

2
1 7
9 8
Case 1: 8
Case 2: 17



and here is my c++ solution link: http://ideone.com/Iw7489

and here is my c++ solution to "Greetings from lightOJ" problem:
#include <iostream>
using namespace std;

int main() {
// your code goes here
int T, a, b;
//T <= 125;
//0 <= a <= 10;
//0 <= b <= 10;
cin >> T;
for (int i = 1; i <= T; i++) {
cin >> a >> b;
cout << "Case " << i << ": " << a+b << "\n";
}

return 0;
}