HDU 1000 A + B Problem(指针版)

114 阅读1分钟

A + B Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 654986    Accepted Submission(s): 204210

Problem Description

Calculate A + B.

 

Input

Each line will contain two integers A and B. Process to end of file.

 

Output

For each case, output A + B in one line.

 

Sample Input

1 1

 

Sample Output

2

 

Author

HDOJ

题目链接:acm.hdu.edu.cn/showproblem…

分析:我的第一道用指针做的题,初学指针,以前也从来没有用过指针,试试水,就来道A+B,大牛就不要喷了,Orz! 

下面给出AC代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int *p,*q,m,n;
 6     int ans;
 7     p=&m;
 8     q=&n;
 9     while(scanf("%d%d",p,q)!=EOF)
10     {
11         ans=*p+*q;
12         printf("%d\n",ans);
13     }
14     return 0;
15 }