UVA 10494-If We Were a Child Again(一流的塔尔苏斯)

Problem C

If We Were a Child Again

Input: standard input

Output: standard output

Time Limit: 7 seconds

 


“Oooooooooooooooh!

If I could do the easy mathematics like my school days!!

I can guarantee, that I’d not make any mistake this time!!”

Says a smart university student!!

But his teacher even smarter – “Ok! I’d assign you such projects in your software lab. Don’t be so sad.”

“Really!!” - the students feels happy. And he feels so happy that he cannot see the smile in his teacher’s face.


The Problem

The first project for the poor student was to make a calculator that can just perform the basic arithmetic operations.

But like many other university students he doesn’t like to do any project by himself. He just wants to collect programs from here and there. As you are a friend of him, he asks you to write the program. But, you are also intelligent
enough to tackle this kind of people. You agreed to write only the (integer) division and mod (% in C/C++) operations for him.


 

Input

Input is a sequence of lines. Each line will contain an input number. One or more spaces. A sign (division or mod). Again spaces. And another input number. Both the input numbers are non-negative integer. The first one may be arbitrarily
long. The second number n will be in the range (0 < n < 231).

 
Output

A line for each input, each containing an integer. See the sample input and output. Output should not contain any extra space.

 
 
Sample Input

110 / 100

99 % 10

2147483647 / 2147483647

2147483646 % 2147483647

Sample Output

1

9

1

2147483646

第一次用java写,曾经从来没看过,今天看了一点主要的输入输出切了一道A+B后,直接来一道高精度的。1A,没有编译器,直接敲完就交,谁给我的勇气?。。。

待会写一篇总结java里面的高精度大数的使用方法

import java.io.*;

import java.util.*;

import java.math.*;
import java.text.*;
public class Main {

		public static void main(String args[]) {

		       Scanner in = new Scanner(System.in);

                       BigInteger a,b;char c;
                       while(in.hasNext()){
		       a = in.nextBigInteger();

                       c=in.next().charAt(0);
		       b = in.nextBigInteger();

		       if(c=='/')
                       System.out.println(a.divide(b));
                       else
                        System.out.println(a.mod(b));

                      }

               }

}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

时间: 2024-11-12 12:16:59

UVA 10494-If We Were a Child Again(一流的塔尔苏斯)的相关文章

uva 10494 If We Were a Child Again

import java.util.Scanner; import java.math.BigInteger; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); BigInteger a,b; String[] s; while(in.hasNextLine()){ s = in.nextLine().split("\\s+"); //正则表达式,

uva 10494 高精度除法

这道题我wa了4次!!!RE了一次,直到看到了RE我才看到了希望,果然,把数组开大一点就过了,小白 在uva上的题好像叙述都不太精确,从来都不说数据最长多少,以至于只能瞎开数组,白白RE了一次,wa的原因是因 为数据类型错了,应该开long long的,我竟然忘了商也可以是大数的,,,唉,还是不够细心,不够认真啊. 贴代码: #include<stdio.h> #include<stdlib.h> #include<string.h> #define ll long l

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

高精度题目列表

JAVA大数类练手 748 - Exponentiation Uva 424 Uva 10106 Uva 465 Uva 10494 POJ 2389 POJ 2756 HDU 1715 HDU 1047 HDU 1297 HDU 1002 HDU 1316 HDU 1865 HDU 1250 HDU 1042 HDU 1753 POJ 1220 HDU 2100 Uva 10023 Uva 10069 HDU 4762 Uva 10497 Uva 10844 HDU 4873 Uva 1478

大数常用计算模板及例题

一.模板&例题 [两个大数相加] string sum(string s1,string s2) { if(s1.length()<s2.length()) { string temp=s1; s1=s2; s2=temp; } int i,j; for(i=s1.length()-1,j=s2.length()-1;i>=0;i--,j--) { s1[i]=char(s1[i]+(j>=0?s2[j]-'0':0)); //注意细节 if(s1[i]-'0'>=10)

UVA 10497 - Sweet Child Makes Trouble(DP+高精度)

题目链接:10497 - Sweet Child Makes Trouble 题意:n个物品,原来物品属于一个地方,现在要把物品重新放回去,问能放几种使得每个物品都与原来位置不同 思路:递推,一开始随便搞了个二维状态,dp[i][j]表示i个物品,有j个位置不同,那么dp[n][n]就是答案,递推式为: dp[i][j] = 1 (j == 0) dp[i][j] = (j - 1) * dp[i - 1][j - 1] + dp[i - 1][j] + (i - j + 1) * dp[i -

UVA - 10497 Sweet Child Makes Trouble

Children are always sweet but they can sometimesmake you feel bitter. In this problem, you will see how Tintin, a five year'sold boy, creates trouble for his parents. Tintin is a joyful boy and is alwaysbusy in doing something. But what he does is no

uva 10497 - Sweet Child Makes Trouble(dp+高精度)

题目链接:uva 10497 - Sweet Child Makes Trouble 题目大意:有个小屁孩很淘气,总是趁父母不在家的时候去拿家具玩,每次拿n个家具玩,但是放回去的时候一定不会将某个物品放回原处,一定要打乱.问说有多少放的方式满足. 解题思路:dp[i]表示说i个数打乱的情况,dp[i]=(dp[i?1]+dp[i?2])?(i?1)每次新增一个数,放在序列的最后一个位置,它的位置一定是正确的,所以一定要和前面i?1个的其中一个交换位置才可以,那么如果选中位置上的物品为错误归放的,

递推+高精度 UVA 10497 Sweet Child Makes Trouble(可爱的孩子惹麻烦)

题目链接 题意: n个物品全部乱序排列(都不在原来的位置)的方案数. 思路: dp[i]表示i个物品都乱序排序的方案数,所以状态转移方程.考虑i-1个物品乱序,放入第i个物品一定要和i-1个的其中一个交换位置,即:考虑i-2个物品乱序,第i-1个和第i个首先在原来的位置,两种方法使得乱序,一种和第i个交换(不能和前i-2个交换,那样成dp[i-1]),还有一种是第i个先和第i-1个交换,再和前i-2个其中一个交换,即,仔细想想,这个和dp[i-1]是不同的交换方法. 另外: 还有二维的dp写法,