UVA 10494 - If We Were a Child Again

UVA Sep 01, 2020

Problem PDF

Solution:

in java:

package mypkg;

import java.math.BigInteger;
import java.util.Scanner;
 class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		BigInteger a,b;
		String c;
		while (in.hasNext()) {
			a=in.nextBigInteger();
			c=in.next();
			b=in.nextBigInteger();
			if (c.compareTo("/")==0) {
                           System.out.println(a.divide(b));
			}
			else{
                           System.out.println(a.remainder(b));
			}

		}
	}

}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/10494/Main.java

in c:

#include<iostream>
#include<algorithm>
#include<sstream>
#include<fstream>
#include<utility>
#include<cstdlib>
#include<cstring>
#include<string>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#define ll long long
#define sc scanf
#define pf printf
#define pi 2*acos(0.0)
using namespace std;
char res[100000];

void dev(char s[],long long int n)
{
    long long int rem=0,i,j=0;
    char a[100000];
    int f=1;
    for(i=0;i<strlen(s);i++)
    {
        rem=s[i]-'0'+rem*10;
        if(rem/n!=0)
        f=0;
        if(!f)
        printf("%lld",rem/n);
        rem=rem%n;
    }
    if(f)
    printf("0");
}

int rem(char s[],long long int n)
{
   long long  int i,rem=0,j;
    for(i=0;i<strlen(s);i++)
    {
        rem=s[i]-'0'+rem*10;
        rem=rem%n;
    }
    return rem;
}


int main()
{
    char s[100000],t;
    long long int i,j,k,l,m,n;
    while(scanf("%s %c %lld",&s,&t,&n)==3)
    {
        if(t=='/')
        {
            dev(s,n);
            printf("\n");
        }

        else
        {
            m=rem(s,n);
            printf("%lld\n",m);
        }
    }
    return 0;
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/blob/master/uva/10494/10494.cpp

Tags

Shipu Ahamed

CSPO® | Partly Product, Project Manager and Partly Software Engineer.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.