zoukankan      html  css  js  c++  java
  • hdu 2101

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2101

    题意:判断两输相加是不是86的倍数;

    思路:直接算就可以;

    代码:

     1 #include<stdio.h>
     2 
     3 int main()
     4 {
     5     int a,b;
     6     while(scanf("%d%d",&a,&b)!=EOF)
     7     {
     8         if((a+b)%86==0)
     9             printf("yes
    ");
    10         else
    11             printf("no
    ");
    12     }
    13     return 0;
    14 }

    之所以写这个博客是因为:把这个题加一个条件(两个数都非常大,甚至超出long long)就可以让这个题变成大数运算模拟的题(模拟加法以及模除)

    注意:由于原题的数据很水,对于真正的大数模拟运算的题,该代码可能存在bug;

    代码:

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<string>
     4 #include<cstring>
     5 
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     string a,b;
    11     while(cin>>a>>b)
    12     {
    13         int a1[100]={0},b1[100]={0};
    14         int i,d=0,s=0;
    15         for(i=a.length()-1;i>=0;i--)
    16         {
    17             a1[d++]=a[i]-'0';
    18         }
    19         for(i=b.length()-1;i>=0;i--)
    20         {
    21             b1[s++]=b[i]-'0';
    22         }
    23         if(d<s)
    24         {
    25             int t=d;
    26             d=s;
    27             s=t;
    28         }
    29         int fg=0;
    30         for(i=0;i<d;i++)
    31         {
    32             int t=a1[i]+b1[i]+fg;
    33             fg=t/10;
    34             a1[i]=t%10;
    35         }
    36         if(fg)
    37         {
    38             a1[i++]++;
    39         }
    40         fg=0;
    41         for(i=i-1;i>=0;i--)
    42         {
    43             int t=fg*10+a1[i];
    44             a1[i]=t/86;
    45             fg=t%86;
    46         }
    47         if(fg==0)
    48             printf("yes
    ");
    49         else
    50             printf("no
    ");
    51     }
    52     return 0;
    53 }

    ---------------------------------------欢迎指正评论-------------------------------------

  • 相关阅读:
    csrf & xss
    android_sqlite
    android_error
    oracle笔记
    android_lesson_1
    mysql 设置编码
    前端进阶Event
    前端进阶Position
    chrome插件开发资料
    dom4j selectNodes
  • 原文地址:https://www.cnblogs.com/x-x-y/p/7232348.html
Copyright © 2011-2022 走看看