HDU 2057 A+B Again 手动解决办法

主要是坑在了空间释放上QAQ,每次gets完之后进行处理,处理完之后必须得重新初始化字符串!!!!

真的是大坑,,一道水题做了一晚上……


题目如下:

A+B Again


Problem Description
There must be many A + B problems in our HDOJ , now a new one is coming.
Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too.
Easy ? AC it !
 

Input
The input contains several test cases, please process to the end of the file.
Each case consists of two hexadecimal integers A and B in a line seperated by a blank.
The length of A and B is less than 15.
 

Output
For each test case,print the sum of A and B in hexadecimal in one line.
 

Sample Input
 
   
+A -A+1A 121A -9-1A -121A -AA
 

Sample Output
 
   
02C11-2C-90


一般方法是这样的:

  1. #include  
  2. int main()  
  3. {  
  4.     long long n,m,v;  
  5.     while(scanf("%llx%llx",&n,&m)==2)  
  6.     {  
  7.         v=n+m;  
  8.         if(v<0)  
  9.         {  
  10.             v=-v;  
  11.             printf("-%llX\n",v);      
  12.         }  
  13.         else  
  14.         printf("%llX\n",v);   
  15.     }    
  16.      return 0;  
  17.  }   

我跳的坑是这样的:


emmm最后还是AC了然而那个大坑是真心不容易跳出来

总结一句,初始化hin重要!!!

你可能感兴趣的:(C语言,HDU,计算机编程,C语言练习)