zoukankan      html  css  js  c++  java
  • hdu 1230 字符串

    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. #include <string>
    4. #include <string.h>
    5. #include <iostream>
    6. #define MAX(a,b) a>b? a:b
    7. using namespace std;
    8. int in[30]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
    9. /*http://acm.hdu.edu.cn/showproblem.php?pid=1230*/
    10. int main()
    11. {
    12. char one[1000], two[100];
    13. int one_seat[50], two_seat[50], three_seat[50];
    14. int one_num, two_num;
    15. memset(one, '', sizeof(one) );
    16. memset(two, '', sizeof(two) );
    17. while(~scanf("%s%s", one, two) )
    18. {
    19. char *p = one, *q = two;
    20. one_num = two_num = 1;
    21. memset(one_seat, 0, sizeof(one_seat) );
    22. memset(two_seat, 0, sizeof(two_seat) );
    23. memset(three_seat, 0, sizeof(three_seat) );
    24. while(1)
    25. {
    26. while( (*p) == ',') p++;
    27. if( (*p) != '')
    28. {
    29. one_seat[one_num++] = atoi(p);
    30. while( (*p) != ',' && (*p) !='') {p++; if( (*p) =='') break; } p++;
    31. }
    32. else break;
    33. }
    34. while(1)
    35. {
    36. if( (*q) != '')
    37. {
    38. two_seat[two_num++] = atoi(q);
    39. while( (*q) != ',' && (*q) != '') {q++; if( (*q) =='') break; } q++;
    40. }
    41. else break;
    42. }
    43. if(one_seat[1] + two_seat[1] == 0 && one_seat[2]+ two_seat[2] ==0) break;
    44. int carry=0, seat=0;
    45. for(int i= one_num-1, j= two_num-1; i>=0 || j>=0 || carry != 0; i--,j--)
    46. {
    47. if(i <= 0) i=0;
    48. if(j <= 0) j=0;
    49. three_seat[i] = (one_seat[i] + two_seat[j] +carry) % in[seat];
    50. carry = (one_seat[i] + two_seat[j] + carry) / in[seat++];
    51. }
    52. int i=0;
    53. while( three_seat[i] == 0)
    54. i++;
    55. for(; i<seat-1; i++)
    56. printf("%d,", three_seat[i] );
    57. printf("%d ", three_seat[i]);
    58. memset(one, '', sizeof(one) );
    59. memset(two, '', sizeof(two) );
    60. }
    61. return 0;
    62. }





    附件列表

    • 相关阅读:
      IIS中安全证书更新
      mac权限相关命令
      Nlog配置Seq日志服务
      WPF Prism8.0中注册Nlog日志服务
      .NET MAUI Preview7 状态预览(8月)
      RPA剖析浏览器API(获取指定页面数据)
      .NET Core Worker Service
      .NET MAUI Preview6 状态预览(7月)
      Digicert GeoTrusy Cloud DV
      【Tomcat8】开启Https及挂载静态文件
    • 原文地址:https://www.cnblogs.com/sober-reflection/p/ab9707b93f313a69a149dd0354e3ad5e.html
    Copyright © 2011-2022 走看看