OJ19
1 // we have defined the necessary header files here for this problem.
2 // If additional header files are needed in your program, please import here.
3 #include <string.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 void add(const char *a, const char *b, char *res)
8 {
9 int ia[220000] = {0}, ib[220000] = {0}, ires[220000]= {0};
10 int la = strlen(a), lb = strlen(b);
11 for(int i = la - 1; i >= 0; i--)
12 {
13 ia[la - 1 - i] = a[i] - 48;
14 }
15 for(int i = lb - 1; i >= 0; i--)
16 {
17 ib[lb - 1 - i] = b[i] - 48;
18 }
19 int maxl = la > lb ? la : lb;
20 int resl = maxl;
21 for(int i = 0; i < maxl; i++)
22 {
23 int sum = (ia[i] + ib[i] + ires[i]);
24 ires[i] = sum % 10;
25 ires[i + 1] = sum / 10;
26 if(i + 1 == maxl && ires[maxl] != 0)
27 resl++;
28 }
29 int first = resl - 1;
30 while(ires[first] == 0 && first != 0) first--;
31 for(int i = first; i >= 0; i--)
32 {
33 res[first - i] = ires[i] + 48;
34 }
35 }
36 char* multiply1(const char* a, const char b, char *ans)
37 {
38 for(int i = 0; i < b - 48; i++)
39 {
40 add(a, ans, ans);
41 }
42 return ans;
43 }
44
45 char* multiplyn(const char *a, const char *b, char *ans)
46 {
47 char tempans[220000] = "0";
48 for(int i = strlen(b) - 1; i >= 0; i--)
49 {
50 char tempb[2000] = "";
51 char tempr[2000] = "0";
52 char zeros[2000] = "";
53 for(int z = 0; z < strlen(b) - 1 - i; z++)
54 {
55 zeros[z] = '0';
56 }
57 //memcpy()
58 // tempb[0] = b[i];
59 multiply1(a, b[i], tempr);
60 strcat(tempr, zeros);
61 add(tempans, tempr, tempans);
62 }
63 strcpy(ans,tempans);
64 return ans;
65 }
66 int main()
67 {
68 // please define the C input here. For example: int n; scanf("%d",&n);
69 // please finish the function body here.
70 // please define the C output here. For example: printf("%d\n",a);
71
72 char ans[220000] = "1";
73 char is[6] = "";
74 int n;
75 while(scanf("%d", &n) != -1)
76 {
77
78 for(int i = 2; i <= n; i++)
79 {
80 //itoa(i, is, 10);
81 sprintf(is, "%d", i);
82 multiplyn(ans, is, ans);
83 printf("%s\n", ans);
84 }
85 printf("%s\n", ans);
86 strcpy(ans, "1");
87 }
88
89 return 0;
90 }
OJ19的更多相关文章
- 可注册两位字母+两位数字com域名大全(到2016-5-12:12时候)
ed03.comed31.comef46.comgv04.comhv04.comib72.comij29.comik03.comim09.comir32.comir94.comiu07.comiv05 ...
- C# Socket学习笔记一
小记:刚接触网络编程觉得网络是个神奇的东西,所以对它就很有兴趣,想了解下网络是如何进行进行数据传输的,那么开始第一天的学习吧!ReadyGo!!! 首先我们要了解一下几点内容: 1.网络中进程之间如何 ...
随机推荐
- C++程序设计实验四 继承
程序源码: #include <iostream> #include <typeinfo> // definitation of Graph class Graph { pub ...
- Windows 从头搭建c++ Eigen 库
虽然目前还在用python实现自己的算法,但是还是有点略微不满足,算法迟早有一天全从python搬到c++上,先给自己立个flag. 前言 由于本人做一些模型的搭建和计算,矩阵运算必然是少不了的,本人 ...
- Mybatis 中传入List实现 批量插入、批量更新、批量删除
1. 批量插入: Mapper层: int insertList(List<UsersModel> list); 对应的mapper.xml: <!--批量插入信息--> &l ...
- Qt使用图片旋转绘制圆环,圆弧类UI界面(方法可适用于winform和WPF等其余UI绘制)
先上效果图: 这个主要是一个试剂杯盘的循环图,相信大家伙一定都想到了使用GDI和三角函数来进行计算,但如果没有实际尝试,可能会踩一些坑,留此文帮助大家方便快捷的绘制出类似圆环的UI效果. 这里主要是使 ...
- golang 手写实现多台机器执行定时任务
多台机器,固定间隔每台分别去执行任务. package main import ( "fmt" "strconv" "time" ) fun ...
- redisTemplate实现分布式锁(释放锁用lua脚本)
package com.xxx.platform.util; import org.springframework.beans.factory.annotation.Autowired; import ...
- 记录一次mybatis中parameterType中使用String和string的区别
今天修改一个问题. xml中使用的是#{xxxx jdbcType=String} 但是这个sql 查询需要用到 in 如果这样查询 会变成 in ( "1,2,3,4,5" ...
- 插入排序C语言
1 #include "stdio.h" 2 #include "stdlib.h" 3 typedef int ElemType; 4 //直接插入排序 5 ...
- C - Frog Jumps
C - Frog Jumps 思路:青蛙跳的问题,青蛙只能跳'R',不能跳'L',问青蛙至少跳多少可以跳过,我们可以这么想这个问题,找到所有R之间的L,看看哪个L多,计算数量即可 代码: #inclu ...
- NGINX一次电脑自己可以访问其它IP访问不了
配制好NGINX 本地电脑curl http..... 正常访问...其它电脑不可以 第一想法防火墙 查一下 firewall-cmd --state not running 然后查下是不是服务开启 ...