PAT (Basic Level) Practise:1017. A除以B
本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数。你需要输出商数Q和余数R,使得A = B * Q + R成立。
输入格式:
输入在1行中依次给出A和B,中间以1空格分隔。
输出格式:
在1行中依次输出Q和R,中间以1空格分隔。
输入样例:
123456789050987654321 7
输出样例:
17636684150141093474 3
【提交代码】
#include <stdio.h>
#include <string.h> #define MAX_LEN (1024) void division(char *str, int n, char *dest, int *r)
{
int div, q;
int k, i, len = strlen(str);
int flag = ; div = ;
k = ;
for(i = ; i < len; i++)
{
div *= ;
div += str[i] - '';
q = div / n;
if(q > )
{
dest[k++] = q + '';
div = div % n;
flag = ;
}
else if (q == && flag != )
{
dest[k++] = q + '';
div = div % n;
}
}
if(k == )
{
dest[k++] = '';
}
dest[k] = '\0';
*r = div;
} int main(void)
{
char dest[MAX_LEN];
char str[MAX_LEN];
int n, r; //printf("input str: \r\n");
scanf("%s", str);
//printf("input n: \r\n");
scanf("%d", &n);
//printf("%s / %d =\r\n", str, n); memset(dest, 0x00, sizeof(dest));
division(str, n, dest, &r);
printf("%s %d", dest, r);
return ;
}
PAT (Basic Level) Practise:1017. A除以B的更多相关文章
- PAT (Basic Level) Practice 1017 A除以B 分数 20
本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数.你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立. 输入格式: 输入在一行中依次给出 A 和 B,中间以 ...
- PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15)
PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15) http://www.patest.cn/contests/pat-b-practise/10 ...
- PAT (Basic Level) Practise (中文)-1039. 到底买不买(20)
PAT (Basic Level) Practise (中文)-1039. 到底买不买(20) http://www.patest.cn/contests/pat-b-practise/1039 小红 ...
- PAT (Basic Level) Practise (中文)- 1022. D进制的A+B (20)
PAT (Basic Level) Practise (中文)- 1022. D进制的A+B (20) http://www.patest.cn/contests/pat-b-practise/1 ...
- PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20)
PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20) http://www.patest.cn/contests/pat-b-practise/1024 ...
- PAT (Basic Level) Practise (中文)-1025. 反转链表 (25)
PAT (Basic Level) Practise (中文)-1025. 反转链表 (25) http://www.patest.cn/contests/pat-b-practise/1025 ...
- PAT (Basic Level) Practise (中文)-1027. 打印沙漏(20)
PAT (Basic Level) Practise (中文)-1027. 打印沙漏(20) http://www.patest.cn/contests/pat-b-practise/1027 本题 ...
- PAT (Basic Level) Practise (中文)-1028. 人口普查(20)
PAT (Basic Level) Practise (中文)-1028. 人口普查(20) http://www.patest.cn/contests/pat-b-practise/1028 某 ...
- PAT (Basic Level) Practise (中文)-1029. 旧键盘(20)
PAT (Basic Level) Practise (中文)-1029. 旧键盘(20) http://www.patest.cn/contests/pat-b-practise/1029 旧键盘上 ...
- PAT (Basic Level) Practise (中文)-1030. 完美数列(25)
PAT (Basic Level) Practise (中文)-1030. 完美数列(25) http://www.patest.cn/contests/pat-b-practise/1030 给 ...
随机推荐
- The APR based Apache Tomcat Native library 异常解决办法
tomat在linux服务器上启动报The APR based Apache Tomcat Native library which allows optimal performance in pro ...
- linux bash: sqlplus: command not found 错误处理
在oracle用户下 ,执行sqlplus命令,抛出如上错误. 解决办法: 1.su oracle 2.cd /home/oracle 3. 执行命令 source .bash_pro ...
- 如何删除href=""中的链接?
答案:在dw中操作,删除 HTML文件的href的链接地址\href="[^"]*"href="" 同理可以在title="[^" ...
- ruby在线学习
http://tryruby.org/ [Heroku空间] 免费ruby空间
- 判断子元素(or属性)是否存在
if(typeof($("#aid").attr("rel"))=="undefined") 即可
- Expression<Func<T, bool>>
public static Expression<Func<T, bool>> True<T>() { return f => true; } public ...
- 把Angular中的$http变成jQuery.ajax()一样,可以让后台(php)轻松接收到参数
最近接到一个手机项目,我决定用ionic + php + mysql来实现.ionic是一个前端框架,主要用于手机端,它融合了html5.css3.angularJS于一体,用起来很顺手. 开始构建项 ...
- S1:new操作符
function Shape(type){ this.type = type || "rect"; this.calc = function(){ return "cal ...
- Zooming MKMapView to fit annotation pins
http://stackoverflow.com/questions/4680649/zooming-mkmapview-to-fit-annotation-pins - (MKCoordinateR ...
- 神奇的NOIP模拟赛 T1 LGTB 玩扫雷
LGTB 玩扫雷 在一个n m 的棋盘上,有位置上有雷(用“*” 表示),其他位置是空地(用“.” 表示).LGTB 想在每个空地上写下它周围8 个方向相邻的格子中有几个雷.请帮助他输出写了之后的棋盘 ...