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.网络中进程之间如何 ...
随机推荐
- 周练3(php反序列化)
serialize()函数 $s = serialize($变量); //该函数将变量数据进行序列化转换为字符串 file_put_contents('./目标文本文件', $s); //将$s保存到 ...
- MySQL突然连接失败
mysql突然连接失败问题 1.报错 MySQL error: 2013, "Lost connection to MySQL server at 'reading initial comm ...
- Wordpress主题twentytwelve修改首页文章摘要
方法:网站后台->外观->编辑->找到content.php文件 路径:wp-content/themes/twentytwelve/ 找到这一句: <?php if ( is ...
- 解决Mac安装Homebrew失败
首先使用Homebrew官网的安装shell命令安装: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebr ...
- Unity中UGUI图片跟随文本自适应方法
字体和图片层级如下 Text添加Content Size Fitter Image设置锚点
- Mysql 字符集的设置和修改
Show variables like 'character%'; //显示目前mysql默认 字符集 显示数据连接字符集 修改字符集 D:\mysql>Net stop mysql // ...
- gitee 操作
腾讯软件搜索 腾讯软件中心-海量软件高速下载 (qq.com) git,下载 git,安装.右键git bash here,输入,Git clone url地址.输入码云用户名密码,下载 $ Git ...
- 记:后端对字符串进行gzip压缩,前端js进行gzip解压
最近有个需求要求对长字符串进行gzip压缩,然后在js进行解压缩的操作: public static void main(String[] args) { try { String longStrin ...
- elastalert部署和使用
一.Elastalert简介 Elastalert是Yelp公司基于python开发的ELK日志告警插件,Elastalert通过查询Elasticsearch中的记录与定于的告警规则进行对比,判断是 ...
- ASP.NET中maxRequestLength和maxAllowedContentLength的区别;上传大文件设置IIS7文件上传的最大大小
https://blog.csdn.net/qq_23663693/article/details/89920039 maxRequestLength表示ASP支持的最大请求大小,而maxAllowe ...