UVA Solution 362 - 18,000 Seconds Remaining- Solution in C, C++ | Volume 3 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Friday, May 5, 2017

UVA Solution 362 - 18,000 Seconds Remaining- Solution in C, C++ | Volume 3

UVA Solution 362 - 18,000 Seconds Remaining- Solution in C, C++ | Volume 3


UVA Online Judge Solution 362 - 18,000 Seconds Remaining| Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=298

Problem Name: 362 - 18,000 Seconds Remaining
Problem Number : UVA - 362 - 18,000 Seconds Remaining
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus

UVA Solution 362 - 18,000 Seconds Remaining- Solution in C, C++ | Volume 3

UVA Solution 362 - 18,000 Seconds Remaining Code in C, CPP:


#include <stdio.h>

int main() {
    int n, test = 0;
    while(scanf("%d", &n) == 1 && n) {
        printf("Output for data set %d, %d bytes:\n", ++test, n);
        int sum = 0, cnt = 0;
        int total = 0, x;
        while(scanf("%d", &x) == 1) {
            sum += x;
            n -= x;
            cnt++;
            if(cnt == 5) {
                printf("   Time remaining: ");
                if(sum == 0)
                    puts("stalled");
                else {
                    int tmp = n*5;
                    printf("%d seconds\n", tmp/sum + (tmp%sum != 0));
                }
                sum = 0;
                cnt = 0;
            }
            total++;
            if(n == 0)
                break;
        }
        printf("Total time: %d seconds\n\n", total);
    }
    return 0;
}

No comments:

Post a Comment