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的更多相关文章

  1. 可注册两位字母+两位数字com域名大全(到2016-5-12:12时候)

    ed03.comed31.comef46.comgv04.comhv04.comib72.comij29.comik03.comim09.comir32.comir94.comiu07.comiv05 ...

  2. C# Socket学习笔记一

    小记:刚接触网络编程觉得网络是个神奇的东西,所以对它就很有兴趣,想了解下网络是如何进行进行数据传输的,那么开始第一天的学习吧!ReadyGo!!! 首先我们要了解一下几点内容: 1.网络中进程之间如何 ...

随机推荐

  1. 初始化控件panel大小和相对父容器居中

    /// <summary> /// 初始化界面大小 /// </summary> protected void InitForm() { int winwith = Scree ...

  2. 前端使用axios如何提交表单请求

    //使用FormData创建参数 let formData = new FormData(); formData.append("jsonData", JSON.stringify ...

  3. 在centos环境下利用docker安装kail

    配置好国内阿里云镜像 vim  /etc/docker/daemon.json {"registry-mirrors":["https://cq20bk8v.mirror ...

  4. Software_programming_tools_IDEA

    13:45:55 key promtoer 快捷键提示插件

  5. Linux 服务器内存异常问题记录

    一.内存异常 1. 问题描述:服务器内存一会儿就增加1G,但也没有看到有消耗内存较大的进程:最后联想到项目最近做ARM架构适配,有变更代码,立马想到使用的SSH组件,一查看就发现有大量的进程: 解决办 ...

  6. Xrdp服务安装配置实现Linux远程桌面访问以及问题处理

    0x00 基础介绍 0x01 安装桌面环境 Ubuntu 系列 0x02 Xrdp 安装使用 How to Install xrdp on Ubuntu ? How to Install xrdp t ...

  7. 03java基础(二)java面向对象

    目录 类和对象的基本使用 基础概念 类的初始化 用new关键字创建对象 创建对象的内存分析 OOP的三大特征 类的封装 类的继承 继承的基础使用 继承基本概念 extends关键字的基本使用 supe ...

  8. 分布式计算 Distributed computing

    分布式计算(Distributed computing),又译为分散式运算,是一门计算机科学,它研究如何把一个需要非常巨大的计算能力才能解决的问题分成许多小的部分,然后把这些部分分配给许多计算机进行处 ...

  9. tesseract-ocr 安装、语言库、使用 随记

    前几日才听说ocr的图片识别功能.觉得很有意思.先体验一下. 地址: GitHub - tesseract-ocr/tesseract: Tesseract Open Source OCR Engin ...

  10. [洛谷/题目] P1562 还是N皇后

    声明 关于科学道理都会放进代码中,但是我们需要先了解一下位运算解这道题目的基础知识 我不是很会专业词语,所以仅介绍原理 位运算基础 众所周知,二进制是0和1 2^3 2^2 2^1 2^0 8 4 2 ...