1001 Reverse Root

本人刚刚开始学习C++,有很多不明白之处,但是单纯看书学习又觉得枯燥。想想还是要 在实践中学习,边做边学,缺什么知识就补什么知道。所以开始OJ做题。以此做个记录。
以下是题目:
1001. Reverse Root
Time limit: 2.0 second Memory limit: 64 MB
The problem is so easy, that the authors were lazy to write a statement for it!
Input
The input stream contains a set of integer numbers Ai (0 ≤ Ai ≤ 1018). The numbers are separated by any number of spaces and line breaks. A size of the input stream does not exceed 256 KB.
Output
For each number Ai from the last one till the first one you should output its square root. Each square root should be printed in a separate line with at least four digits after decimal point.
Sample
input
1427 0

876652098643267843
5276538
output
2297.0716
936297014.1164
0.0000
37.7757

以下是AC的CODE

#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
 using namespace std;
int main()
 {
    int i=0,j;
    double a;
    vector<double> x;
    while(cin>>a)
    {
       x.push_back(sqrt(a));
       i++;
    }

    for(j=i-1;j>=0;j--)
     printf("%.4f\n", x[j]);
     return 0;
}

本题一开始没有用VECTOR库,虽然CODEBLOCKS通过了,但是OJ一直报错。Runtime error (access violation),为什么会报错,这个问题还没有解决。留做思考
以下是报错的CODE

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
  double a[3000];
  int i=0 ,j;
  double b;
  while (cin>>a[i])
     ++i;
    for (j=i-1;j>=0;j--)
   {
    b=sqrt(a[j]);
     printf("%.4lf\n",b);
   }
  return 0;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值