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.网络中进程之间如何 ...
随机推荐
- 容忍和污点Taint和Toleration
说明: Taint在一类服务器上打上污点,让不能容忍这个污点的Pod不能部署在打了污点的服务器上. Toleration是让Pod容忍节点上配置的污点,可以让一些需要特殊配置的Pod能够调用到具有 污 ...
- Java学习笔记(三)java方法
学习笔记3 Java方法 一.什么是方法 System.out.println() 是什么 System是一个类,out是一个对象,println()就是一个方法 意思是调用System中的out对象 ...
- ConvFormer: Closing the Gap Between CNN and Vision Transformers概述
0.前言 相关资料: arxiv github 论文解读 论文基本信息: 发表时间:arxiv2022(2022.9.16) 1.针对的问题 CNN虽然效率更高,能够建模局部关系,易于训练,收敛速度快 ...
- 面了几个说自己精通 Vue 的同学,实在一言难尽……
请说一下响应式数据的原理 默认 Vue 在初始化数据时,会给 data 中的属性使用 Object.defineProperty 重新定义所有属性,当页面到对应属性时,会进行依赖收集 (收集当前组件中 ...
- P1886 滑动窗口 /【模板】单调队列
滑动窗口 /[模板]单调队列 题目描述 有一个长为 \(n\) 的序列 \(a\),以及一个大小为 \(k\) 的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小 ...
- 如何优雅地写LCD接口的使用
通过面向对象方法进行实现,可以多学习 参考链接: http://www.wujique.com/2021/05/16/lcd%e9%a9%b1%e5%8a%a8%e5%ba%94%e8%af%a5%e ...
- 如何使用新版bing(支持ChatGPT)
就在今天,2023年2月8日,微软正式将ChatGPT引入Bing 搜索引擎迎来新时代 如何体验支持ChatGPT的新版bing? 一.重要说明 请自备TiZi 本文以PC端为例 目前,新版 Bing ...
- Software_programming_EnterpriseArch_ServiceWithSingleTonFactory
19:50:31 <UML 模式和应用> P322 系统需要支持多种第三方外部服务,例如费用计算,授权服务,库存系统,都具有不同的API, 而且还无法改变. 解决方案之一: 使用 单例模式 ...
- Linux系统安全:SNAT和DNAT的实现
一.SNAT1.SNAT实验目的公司内有2台机器,但是只有一个公网ip,利用SNAT技术实现2台私网地址都可以访问公网. 2.SNAT实验环境准备①三台服务器:PC1客户端.PC2网关.PC3服务端. ...
- Xrdp服务安装配置实现Linux远程桌面访问以及问题处理
0x00 基础介绍 0x01 安装桌面环境 Ubuntu 系列 0x02 Xrdp 安装使用 How to Install xrdp on Ubuntu ? How to Install xrdp t ...