zoukankan      html  css  js  c++  java
  • hdu 4608 I-number 大整数

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

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <algorithm>
     4 #include <iostream>
     5 #include <cstring>
     6 #include <queue>
     7 #include <vector>
     8 #define maxn 105000
     9 using namespace std;
    10 
    11 int len;
    12 char a[maxn],b[maxn]; 
    13 
    14 
    15 int getsum(){
    16     int ans = 0; //printf("%d
    ",len);
    17     for(int i=0;i<len;i++){
    18         ans += a[i] - '0';
    19     }// printf("ans   %d
    ",ans);
    20     return ans;
    21 }
    22 void add(int num){
    23     int incnt = 0;
    24     int temp = a[0] - '0'  + num;   //printf("temp  %d
    ",temp);
    25     
    26     if(temp > 9){
    27         incnt = 1;  
    28         a[0] = temp - 10 + '0';  //printf("*** %c %d
    ",a[0],temp);
    29     }
    30     else    a[0] = temp + '0';
    31     int cnt = 1;
    32     while(incnt && cnt < len){   
    33         temp = a[cnt] - '0' + incnt;
    34         if(temp>9){
    35             incnt = 1;
    36             a[cnt] = temp - 10 + '0';
    37         }
    38         else {incnt = 0; a[cnt] = temp + '0';}
    39         cnt++;
    40     }
    41     if(incnt && cnt == len){
    42         a[cnt] = '1';
    43         len ++;
    44     }
    45 }
    46 
    47 int main()
    48 {
    49     //if(freopen("input.txt","r",stdin)== NULL)  {printf("Error
    "); exit(0);}
    50 
    51     int T;
    52     cin>>T;
    53     while(T--){
    54         
    55         int numzero = 0;
    56         scanf("%s",b);
    57         
    58         while(b[numzero] == '0'){
    59             numzero++; 
    60         }
    61         
    62         int cnt = numzero;
    63         len = 0;
    64         for(int i=0;b[cnt]!='';i++) {a[i] = b[cnt++]; len++; }
    65 
    66         for(int i=0;i<len/2;i++){
    67             int temp = a[i];
    68             a[i] = a[len-1-i]; 
    69             a[len-1-i] = temp; 
    70         } 
    71         int sum = getsum()%10;  //printf("%d %d
    ",len,sum);
    72         if(sum == 0) sum = 9;
    73         int time = 0;
    74         while(sum != 0 && time < 20){
    75             add(1); //printf("%d %d
    ",len,sum);
    76             sum = getsum()%10;
    77             time++; 
    78         }
    79         while(numzero--) printf("0");
    80         for(int i=len-1;i>=0;i--) printf("%c",a[i]);
    81         printf("
    ");
    82     }
    83 }
    View Code
  • 相关阅读:
    linux网络管理之netstat命令
    linuxping命令
    linux网络管理-ip
    linux网络管理--网络配置及命令
    汇编基础整理
    windows编辑文本和unix编辑文本的回车符问题
    Zend Studio 8.0.1 新建远程项目无法展示远程项目列表的问题
    HTTPS 服务器搭建
    mysql中的JOIN用法总结
    tcpdump使用和TCP/IP包分析
  • 原文地址:https://www.cnblogs.com/acmdeweilai/p/3210419.html
Copyright © 2011-2022 走看看