随笔 - 87  文章 - 279  trackbacks - 0
<2024年8月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

潜心看书研究!

常用链接

留言簿(19)

随笔分类(81)

文章分类(89)

相册

ACM OJ

My friends

搜索

  •  

积分与排名

  • 积分 - 213198
  • 排名 - 116

最新评论

阅读排行榜

评论排行榜

原题:

Calculate a + b
 
Input

The input will consist of a series of pairs of integers a and b,
separated by a space, one pair of integers per line. 

Output

For each pair of input integers a and b you should output the sum
 of a and b in one line,and with one line of utput for each line in input.

Sample Input
1 5

Sample Output
6

Hint
Use + operator

#include<iostream>
#include
<string>
using namespace std;


int main()
{
    
string a,b;
    
char *= NULL;
    
long a_len = 0,b_len = 0,c_len=0,min_len;
    
int one_bit = 0;
    
bool flag = false;
    
while(cin>>a>>b)
    
{
        
if (a[0]!='-'&&b[0]!='-')
        
{
            a_len 
= a.length();
            b_len 
= b.length();
            c_len 
= (a_len>b_len?a_len:b_len)+1;
            min_len 
= a_len<b_len?a_len:b_len;
            c 
= new char[c_len+1];
            c[c_len] 
= '\0';
            c[
0= 'A';
            
while(min_len>0)
            
{
                one_bit
=int(a[a_len-1])+int(b[b_len-1])-96;
                
if(flag)
                    one_bit
++;
                
if(one_bit>9)
                
{
                    one_bit 
-= 10;
                    flag 
= true;
                }

                
else
                    flag 
= false;
                c[c_len
-1= char(one_bit+48);
                one_bit 
= 0;
                c_len
--;
                min_len
--;
                a_len
--;
                b_len
--;
            }

            
if(a_len==0)
            
{
                
while(b_len>0)
                
{
                    one_bit
=int(b[b_len-1])-48;
                    
if(flag)
                        one_bit
++;
                    
if(one_bit>9)
                    
{
                        one_bit 
-= 10;
                        flag 
= true;
                    }

                    
else
                        flag 
= false;
                    c[c_len
-1= char(one_bit+48);
                    one_bit 
= 0;
                    c_len
--;
                    b_len
--;
                }

            }


            
if(b_len==0)
            
{
                
while(a_len>0)
                
{
                    one_bit
=int(a[a_len-1])-48;
                    
if(flag)
                        one_bit
++;
                    
if(one_bit>9)
                    
{
                        one_bit 
-= 10;
                        flag 
= true;
                    }

                    
else
                        flag 
= false;
                    c[c_len
-1= char(one_bit+48);
                    one_bit 
= 0;
                    c_len
--;
                    a_len
--;
                }

            }

            
            
if(flag)
                c[
0= '1';
        }


        
if (flag)
            cout
<<c<<endl;
        
else
            cout
<<++c<<endl;
        flag 
= false;
        c 
= NULL;
    }

    

    
return 0;
}

这是当时提交的源程序,本以为要考虑负数的,原来不用......
posted @ 2006-02-08 02:15 豪 阅读(2511) | 评论 (27)编辑 收藏
同济大学的 Online Judge -http://acm.tongji.edu.cn/
浙江大学的 Online Judge -http://acm.zju.edu.cn/
北京大学的 Online Judge -http://acm.pku.edu.cn/
吉林大学的 Online Judge -http://acm.jlu.edu.cn/
四川大学的 Online Judge -http://cs.scu.edu.cn/acm
汕头大学的 Online Judge -http://acm.stu.edu.cn/
中科大的 Online Judge -http://acm.ustc.edu.cn/index.php
哈工大的 Online Judge -http://acm.hit.edu.cn/acm.php
西班牙的 Universidad de Valladolid -http://acm.uva.es/
俄罗斯乌拉尔大学 -http://acm.timus.ru/
posted @ 2006-02-07 17:14 豪 阅读(1273) | 评论 (2)编辑 收藏
年初八,我回来了.

记得在清远的时候,同学朋友听到我初八回去的时候,都是那一脸的惊讶,然后都很不由自主地问我回去做什么,然后我说项目还没做完,然后他们都竖起拇指,说我厉害.

我很感谢朋友们的称赞,可是真的那么厉害吗?也许我没什么自信.虽然人家说,大一做项目赚钱已经很厉害啦,可是就我知道,我在做的项目,根本没有什么深度可言,只是一些逻辑上的组合罢了.

记得每次回去的时候,爸爸都说,要读好书,先不要想着赚钱.爸爸说得是有道理的,放假后每天在赶项目,每天在重复相同的事情,觉得真的有点无聊,有点郁闷......但我又想,拿点经验吧,总比看了书,不实践好......

人有时候就是很奇怪,经常自我矛盾,不过我想这次我是不会的了,我已经决定暂时不在做项目了,因为我深知自己的基础差,记得xmm所过,只要努力,哪个方向都会成功的,所以决定了还是先看看书,搞下acm好了,最近发现,老是做项目,人会变得迟钝......



posted @ 2006-02-06 00:44 豪 阅读(216) | 评论 (0)编辑 收藏

终于也体会到

连续几天工作10多小时的滋味....

不过也值得,没吃过苦,是应该吃点的....

posted @ 2006-01-23 01:21 豪 阅读(319) | 评论 (1)编辑 收藏

花了一天的时间,终于完成管理地区的功能.

本以为这个功能很简单,但做起来,很多的细节要注意,这样堆积起来,就是时间了.

行业管理今天是做不完的了,明天再奋斗吧.


Ep:做功能的时候,是应该把功能想清楚再做的.

posted @ 2006-01-21 00:03 豪 阅读(320) | 评论 (0)编辑 收藏
仅列出标题
共18页: First 10 11 12 13 14 15 16 17 18