题目链接:http://acm.jlu.edu.cn/joj/showproblem.php?pid=1379

解题心得:

1,基本的语法不要弄错,当时做的时候,memset用错了,错因是把第二个参数传为数组的大小,第三个参数传为要设的值了,实际应该是参数二为要设的值,参数三为数组大小,并且为整型数组赋值时第二个参数只有为0或-1时才能达到预期效果。

2,在用标准库中的集合和数组时,一定要考虑清楚什么时候该清空和什么时候该设为空,否则就出现怎么都改不对的错误,我就是困在这儿的!!!

3,用visit数组统计各位数字的个数自认为是个挺好的想法,可以看作是思想的进步

  1. #include <stdio.h>
  2. #include <string.h>
  3. char input[81];
  4. char result[15][81];
  5. int visit[10];
  6. void SetResult(int i)
  7. {
  8. int j,k,len;
  9. memset(visit,0,sizeof(visit));
  10. if(i == 0)
  11. {
  12. len = strlen(input);
  13. for(j = 0;j < len;j++)
  14. visit[input[j] - '0']++;
  15. }
  16. else
  17. {
  18. len = strlen(result[i - 1]);
  19. for(j = 0;j < len;j++)
  20. visit[result[i - 1][j] - '0']++;
  21. }
  22. k = 0;
  23. for(j = 0;j < 10;j++)
  24. {
  25. if(visit[j] >= 10)
  26. {
  27. int a = visit[j] / 10;
  28. int b = visit[j] % 10;
  29. result[i][k] = a + '0';
  30. result[i][k + 1] = b + '0';
  31. result[i][k + 2] = j + '0';
  32. k += 3;
  33. }
  34. else if(visit[j] > 0)
  35. {
  36. result[i][k] = visit[j] + '0';
  37. result[i][k + 1] = j + '0';
  38. k += 2;
  39. }
  40. }
  41. }
  42. bool Find(int i,int& first)
  43. {
  44. if(strcmp(result[i],input) == 0)
  45. {
  46. first = -1;
  47. return true;
  48. }
  49. int j;
  50. for(j = 0;j < i;j++)
  51. {
  52. if(strcmp(result[j],result[i]) == 0)
  53. {
  54. first = j;
  55. return true;
  56. }
  57. }
  58. return false;
  59. }
  60. int main(int argc, char* argv[])
  61. {
  62. int b_num;
  63. while(scanf("%d",&b_num) != EOF)
  64. {
  65. while(b_num--)
  66. {
  67. while(scanf("%s",input) && strcmp(input,"-1") != 0)
  68. {
  69. int i;
  70. bool find = false;
  71. memset(result,0,sizeof(result));//每次处理一个字符串都应该将result设为空
  72. for(i = 0;i < 15;i++)
  73. {
  74. SetResult(i);
  75. if(i == 0)
  76. {
  77. if(strcmp(result[i],input) == 0)
  78. {
  79. printf("%s is self-inventorying/n",input);
  80. find = true;
  81. break;
  82. }
  83. }
  84. else
  85. {
  86. int first;
  87. if(Find(i,first))
  88. {
  89. if(first == i - 1)
  90. printf("%s is self-inventorying after %d steps/n",input,i);
  91. else
  92. printf("%s enters an inventory loop of length %d/n",input,
  93. i - first);
  94. find = true;
  95. break;
  96. }
  97. }
  98. }
  99. if(!find)
  100. printf("%s can not be classified after 15 iterations/n",input);
  101. }
  102. printf("/n");
  103. }
  104. }
  105. return 0;
  106. }

JD_Source Code for problem 1379相关推荐

  1. Code Jam Problem D. GoroSort

    题目来源:https://code.google.com/codejam/contest/dashboard?c=975485#s=p3 题目感觉非常不错,有思考的深度! 可以参考官方给出的解析:ht ...

  2. 安全研究 # Neural Network-based Graph Embedding for Cross-Platform Binary Code Similarity Detection

    论文分享<Neural Network-based Graph Embedding for Cross-Platform Binary Code Similarity Detection> ...

  3. js promises 踩坑 填坑 We have a problem with promises

    We have a problem with promises promise 填坑 对于 promise return 与否,结果真的不一样哦. By: Nolan Lawson Published ...

  4. 对Oracle中索引叶块分裂而引起延迟情况的测试和分析

    在版本10.2.0.4未打上相关one-off补丁的情况下,分别对ASSM和MSSM管理模式表空间进行索引分裂测试,经过测试的结论如下: l  在10gr2版本中MSSM方式是不能避免索引分裂引起交易 ...

  5. how-to-get-a-job-in-deep-learning

    http://blog.deepgram.com/how-to-get-a-job-in-deep-learning/ How to Get a Job In Deep Learning 22 SEP ...

  6. 2018 东北地区大学生程序设计竞赛(ABEHIK)

    HDU6500:Problem A. Game with string 题意: 给你一个字符串s以及它的m个子串的首尾位置,现在Alice和 Bob两个人轮流在任一子串的前面或者后面加1个字符,要求加 ...

  7. 【POJ】【2449】Remmarguts' Date

    K短路/A* 经(luo)典(ti) K短路题目= = K短路学习:http://www.cnblogs.com/Hilda/p/3226692.html 流程: 先把所有边逆向,做一遍dijkstr ...

  8. NDC 2010视频下载:看看其他微软平台程序员们都在做什么

    原文地址:<NDC 2010视频下载:看看其他微软平台程序员们都在做什么> NDC(Norwegian Developers Conference,挪威开发者大会)是一年一度的挪威最大的微 ...

  9. COMP0037 Coursework Investigating Path Planning Algorithms

    COMP0037 Coursework 1 Term 2, 2019 "Path Planning in a Known World" Investigating Path Pla ...

  10. windows ubuntu Android studio安装好启动没反应解决方法

    2019独角兽企业重金招聘Python工程师标准>>> 参考:http://blog.csdn.net/qq305013720/article/details/8934152 目前有 ...

最新文章

  1. R假设检验之Mann-Kendall趋势检验法(Mann-Kendall Trend Test)
  2. 3D打印神经电极有助于将大脑连接到电脑
  3. maven私服nexus搭建(windows)
  4. ButterKnife Zelezny导入不成功遇到的问题
  5. java 显示天气的小程序_超级简单的微信小程序获取今日天气预报代码 小程序获取七日天气...
  6. Verilog的数据流、行为、结构化与RTL级描述
  7. 数据库计算机报告,外文数据库计算机检索报告实例.pdf
  8. C++STL中的priority——queue
  9. Win32下对多个的线程句柄的关闭的控制(上)
  10. 孔浩老师的java视频
  11. 南方CASS9.0软件资源下载附安装教程
  12. 创维电视安装第三方app
  13. CodeForces 645D Robot Rapping Results Report
  14. adobe清理工具_Adobe终于通过其新的渐变工具实现了这一点-UX评论
  15. 原生js写网页下拉菜单
  16. oracle11g安装教程_带有Oracle Digital Assistant和Fn Project的会话式UI
  17. 兰州大学本科生(学士学位)LaTeX模板-2021版
  18. Matlab 主曲率、平均曲率、高斯曲率
  19. android短信接受震动,Android中实现拨打电话、发送短信、响铃、震动和获取当前时间...
  20. PythonRedis 无序集合set、有序集合zset操作

热门文章

  1. 手机背景图片在安卓手机上不显示
  2. Windows 8实用窍门系列:1.使用Xaml+C#开发第一个Metro Style应用程序
  3. 关于《PHP任务学习》的说明
  4. php 图像居中裁剪函数,PHP 实现的自定义图像居中裁剪函数示例
  5. 分别使用多线程\多进程\协程+paramiko在华为交换机批量快速进行配置(eNSP模拟器)
  6. ELK详解(九)——Logstash多日志收集实战
  7. Tomcat详解(十一)——Tomcat管理
  8. React 服务端渲染完美的解决方案
  9. 济宁a货翡翠,芜湖a货翡翠
  10. Linux网络基础番外篇(IP、MAC、TCP)