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.网络中进程之间如何 ...
随机推荐
- Matplotlib 实现画中画
需要导入的包 inset_axes 要实现画中画,即在原画轴上添加新轴,需要用到mpl_toolkits.axes_grid1.inset_locator的inset_axes. 基本用法 new_a ...
- Head First Python(第2版)书籍 重视大脑的学习指南
Head First Python(第2版)PDF高清版书籍免费下载地址 提取码:08eo 内容简介 · · · · · · 你想过可以通过一本书就学会Python吗?<Head First ...
- vue样式穿透 滚动条隐藏 原生样式修改
样式穿透:deep,否则可能不能覆盖原有样式,vue2使用/v-deep/或者::v-deep,或者取消scoped,但不推荐,因为会影响到其他页面样式 <style lang="sc ...
- 096_mulesoft with salesforce _01
https://docs.mulesoft.com/mule-runtime/3.5/connect-with-salesforce-example https://www.youtube.com/w ...
- 初学银河麒麟linux笔记 第四章 windows中开发的QT程序适配linux的修改——error: ‘QT_WARNING_DISABLE_DEPRECATED’ does not name a type
QT程序本身在windows中进行开发的,移植到linux系统上进行编译后发现了不少问题,需要一一进行修改 1.系统时间修改 首先是系统时间问题 SYSTEMTIME current_date_tim ...
- 19JS输出杨辉三角
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 12组-Alpha冲刺-6/6
12组-Alpha冲刺-6/6 一.基本情况 队名:字节不跳动 组长博客:https://www.cnblogs.com/147258369k/p/15573118.html 小组人数:10人 二.冲 ...
- apk文件结构
APK (Android Package) 文件,是一个后缀名为.apk的压缩文件,APK文件中包含了一个Android应用程序的所有内容,是Android平台用于安装应用程序的文件. assets ...
- [2] Bert 论文精读
BERT是NLP领域让预训练这件事情出圈的工作. 开篇Introduction介绍了两类主流的预训练方法: 1.feature-based,即基于特征的,即我首先通过预训练得到一些比较好的特征,然后将 ...
- PowerShell Regex
PowerShell默认按每一行遍历去匹配模式 比如"aaa`nbbb"用"a.*b"是匹配不到的 需要用"(?s)a.*b"来匹配 1. ...