UVA10494 If We Were a Child Again

2023-11-21 19:49
文章标签 child uva10494

本文主要是介绍UVA10494 If We Were a Child Again,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

yiyi :

看了题目,以为整数只要用int 来存就够了,谁知道交了好几遍都不可以ac,后来把数据改成long类型的才可以,还是不是很懂什么时候会溢出,好坑,不开心!!!

“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

答案:

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;int main (){char a[100000], ch;long  a1[100000], c1[100000], b, x;int lena;while (scanf("%s %c %ld", a, &ch, &b) != EOF) {lena = strlen(a);memset(a1, 0, sizeof(a1));memset(c1, 0, sizeof(c1));for (int i = 1; i <= lena; i++) {a1[i] = a[i - 1] - 48;}x = 0;for (int i = 1; i <= lena; i++) {c1[i] = (x * 10 + a1[i]) / b;x = (x * 10 + a1[i]) % b;}int lenc = 1;if (ch == '/') {while (c1[lenc] == 0 && lenc < lena)lenc++;for (int i = lenc; i <= lena; i++) printf("%ld",c1[i]);printf("\n");}if (ch == '%') {printf("%ld\n", x);}memset(a, 0, sizeof(a));}return 0;
}

这篇关于UVA10494 If We Were a Child Again的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/404666

相关文章

nth-child 和 nth-of-type 的区别

先看案例: <ul class="demo"><p>p</p><li>one</li><li>two</li><div>div</div></ul> 区别: ele:nth-child: 选择的对象包含父元素下所有子元素ele, 如上 ul.demo 下的子元素包含 p,li,div; ele:nth-of-type: type指的是类型,选择的对象包含父元素下所有的子元素ele,并且必须是

启动Tomcat报错:A child container failed during start

在之前的工作和学习当中,有碰到过很多未知的,在当时看来十分令人疑惑的问题。当时的解决手段简单粗暴,就是直接百度,搜到对应的解决方案,直接抄过来试试,不行再换,直到问题消失,程序可以正常跑了,立马就不管不问了,认为解决了问题。其实这样很不好,一方面是问题消失了,但并不是真正的被解决了。另一方面则是,自己对这个问题没有更深的感悟和记录,以后碰到同样或者类似的问题,还是没有掌握解决的方法。只依靠百度搜索

VUE之Router命令行警告:Named Route ‘Home‘ has a default child route. 解决办法

Named Route ‘Home’ has a default child route. When navigating to this named route (:to=“{name: ‘Home’”), the default child route will not be rendered. Remove the name from this route and use the name

CSS选择器的魔法:探索:not-child()与:nth-child()

CSS选择器是前端开发中的强大工具,它们允许我们以精确的方式选择和操作网页上的元素。在这篇文章中,我们将深入探讨两个非常有用的CSS选择器::not-child()和:nth-child()。通过这些选择器,我们可以创建动态且具有吸引力的网页布局。 :not-child():排除特定元素 :not-child()选择器允许我们排除特定元素,从而对其他元素应用样式。这在创建复杂的布局时非常有用,

Ripro主题化C位系列演示站可调用内页图于视频资源、素材下载站O-子主题ripro-child

详情: RiPro主题版本:网站演示站点可用图片 利于视频资源、素材下载站SEO-子主题 PHP版本要求:7.2及以上 当前版本:V8.0 主题设置:全功能后台设置,无需改代码 主题特色:无需替换RIPRO原主题包任何内容即可实现后台全功能开关修改!!! 下载地址: Ripro主题化C位系列演示站可调用内页图于视频资源、素材下载站O-子主题ripro-child-彩虹兔_YUENOS

CSS3中first-child、last-child、nth-child、nth-last-child

1.单独指定第一个子元素、最后一个子元素的样式 <style type="text/css"> li:first-child{   background:yellow; } li:last-child{    background:blue; } </style>   2.对指定序号的子元素使用样式 <style type="text/css"> li:nty-chil

Codeforces Round #250 (Div. 1) D. The Child and Sequence

最近狂刷DS也算是有所进步了 但是这题还是想得太简单了,直接敲了一个单点更新,区间求和的线段树上去,结果就GG了 注意到取模引起变化是当取模的数小于mod的时候,因此维护一个区间最大值,可以判断该区间是不是有需要取模的数(算是剪枝吧 #include <algorithm>#include <iostream>#include <iomanip>#include <cstring>

org.apache.hadoop.mapred.YarnChild: Error running child : java.lang.UnsupportedClassVersionError: Qu

既起到了一批新机器,安装了不少服务后,运行Sqoop,发现报错。 2019-05-24 10:46:40,798 FATAL [main] org.apache.hadoop.mapred.YarnChild: Error running child : java.lang.UnsupportedClassVersionError: QueryResult : Unsupported major

If We Were a Child Again(大数除法、求余)

Description         “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 smar

CSS3---first-child或者nth-child(1) 不起作用的原因

一、零碎 1、first-child、last-child、nth-child(n)、nth-child(2n)、nth-child(2n-1)、nth-child(odd)、nth-child(even)、nth-last-child(3)(倒数第三个) 注意点: 选择器匹配属于其 父元素的第 N 个子元素, 不论元素的类型。 1、先找到该伪类调用者(元素)的父类 2、其