Você está na página 1de 5

10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems

UAB – 2005: Problem 4: Push


Ups with Blaze

JULY 27, 2009AUGUST 8, 2013 / SHAHAB

i
4 Votes

At UAB football games, Blaze does push ups after each Blazer score.
After the first Blazer touchdown (and point after), Blaze does 7
push ups. After the second touchdown and point after, the score is
now 14 and Blaze does 14 push ups.

Write a program that calculates how many total push ups Blaze
does during the whole game. Assume that only 7 point touchdowns
(including the point after) occur. Prompt for the final score and
print out how many push ups Blaze has done.

Example 1:
Enter final score: 21
Push ups: 42

Example 2:
Enter final score: 7
Push ups: 7
?
Critical TestCases
https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 1/5
10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems

Critical TestCases
1 Enter final score: 0
2 Push ups: 0
3
4 Enter final score: 14
5 Push ups: 21
6
7 Enter final score: 28
8 Push ups: 70
9
10 Enter final score: 35
11 Push ups: 105
12
13 Enter final score: 42
14 Push ups: 147
?
Solution in C/C++
1 // @BEGIN_OF_SOURCE_CODE
2
3 #include <cstdio>
4
5 using namespace std;
6
7 int main (int argc, char *argv [])
8 {
9 int finalScore;
10 printf ("Enter final score: ");
11 scanf ("%d", &finalScore);
12
13 int pushUps = 0;
14 for ( int i = 7; i <= finalScore; i = i + 7 )
15 pushUps = pushUps + i;
16
17 printf ( "Push ups: %d\n", pushUps );
18
19 return 0;
20 }
21
22 // @END_OF_SOURCE_CODE

https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 2/5
10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems
Advertisements

Easy Problems

5 thoughts on “UAB – 2005: Problem


4: Push Ups with Blaze”

1. Tanvir
APRIL 21, 2011 AT 9:39 PM
plz tell me the problem ID of it in UVA.

i
Rate This

2. Tausiq
APRIL 22, 2011 AT 12:25 AM
@Tanvir
this problem is from a high school programming contest .. not
from UVa online judge

i
Rate This
3. Lenz Lawson
https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 3/5
10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems

3. Lenz Lawson
JANUARY 11, 2016 AT 12:15 AM
this a typical beginner’s program for this problem:

#include
int main()
{
int score,i,pushup=0;
printf(“please enter the final score: “);
scanf(“%d”,&score);
printf(“\n”);
if(score%7==0){
for(i=1;i<=score/7;i++){
pushup=pushup+7*i;
}
}
else{
printf(" please enter a multiple of 7.\n");
}
printf("\n");
printf("the total number of push-ups is %d",pushup);
printf("\n");
return 0;
}

i
Rate This

4. Mike Blap
APRIL 5, 2017 AT 6:20 AM
I think I have this working in Golang:

package main

import (
“fmt”
)

func main() {
score := 21
tally := tally(score)
fmt.Println(tally)
}

func tally(score int) int {


https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 4/5
10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems

func tally(score int) int {


div := score / 7
var hm int
for div > 0 {
hm += 7 * div
div -= 1
}
return hm
}

i
Rate This

5. ljnissen
AUGUST 21, 2017 AT 3:30 PM
This is my Ruby solution:

print “Final score: ”


score = gets.to_i
touchdowns = score / 7
pushups = 0

(1..touchdowns).each do |i|
i +=
pushups = pushups + 7*i
end
print “Number of push-ups: “, pushups

i
Rate This

https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 5/5