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. MySQL的Temporary Files存放路径

    在Linux环境中MySQL用TMPDIR环境变量来设置temporary files的路径,如果没有设置,MySQL会用系统默认 /tmp, /var/tmp或/usr/tmp. 1.当排序时(OR ...

  2. cisco恢复IOS文件的方法

    cisco IOS恢复的方法很多,这里使用TFTP方法恢复. 当你delete flash: 后 路由器重启将不能工作,这时要恢复IOS 把你备份好的IOS文件放到TFTP目录里面. > IP_ ...

  3. Java实现台球游戏的动画实现相关代码

    package com.bjsxt;//scr中新建的包packageimport java.awt.*;import javax.swing.*;public class BallGame exte ...

  4. mysql 5.7 gtid 主从复制

    GTID中slave端的binlog是必须开启的,目的是记录执行过的GTID 主库#开启gtidlog-bin=mysql-binexpire_logs_days = 5binlog_format=r ...

  5. matplotlib 在同一张图中显示两种图例

    L1=plt.legend(['ManyShot','FewShot'],loc='upper left') #保存为L1 plt.legend(['ManyShot','FewShot'],loc= ...

  6. CentOS6.8安装docker教程

    在VMware新安装CentOS6.8系统 CentOS6.8可在阿里镜像库下载: https://mirrors.aliyun.com/centos-vault/6.8/isos/x86_64/ 在 ...

  7. Python中Websocket的实现及基本原理

    一.什么是 WebSocket ? WebSocket 是一种标准协议,用于在客户端和服务端之间进行双向数据传输.但它跟 HTTP 没什么关系,它是基于 TCP 的一种独立实现. 以前客户端想知道服务 ...

  8. 面试题 --MySQL事务

    3.1 说一说你对数据库事务的了解 事务可由一条非常简单的SQL语句组成,也可以由一组复杂的SQL语句组成.在事务中的操作,要么都执行修改,要么都不执行,这就是事务的目的,也是事务模型区别于文件系统的 ...

  9. bpmn的依赖注入

    主要对象 new BPMN对象时,流程及对象结构如下图 依赖注入 在初始化bpmn对象时有传入additionalModules进行自定义操作,具体是如何实现这种模块化的管理,主要是用到了依赖注入ht ...

  10. python3.7安装Anaconda3+tensorflow2.1中遇到的问题

    最近想搞深度学习,就开始装tensorflow,其中也是遇到了一些问题,希望给遇到同类问题的童鞋一些提示.... 因为之前一直用的python3.7,虽然网上很多建议装python3.5版本tenso ...