hc5181667 2022-09-26 17:22 采纳率: 50%
浏览 29
已结题

输入字符串和一个整数,结束不了循环

循环结束不了,一直在输入。poj1001
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
int main()
{
    char s[199]={'\0'};

    int n=0,x=0;

while(scanf("%s%d", s, &n) == 2) {

    x=0;
    int di = 1, num = 0;
    int a[1000000];
    a[0] = 1;
    int t;
    int nn[100];
    int id = 0;
    int count = 0, f = 0;
    for (int i = 0; i < strlen(s); ++i) {
        if (f) {
            id++;
        }
        if (s[i] == '.') {
            f = 1;
        } else {
            a[count++] = int(s[i] - '0');
        }

    }
    int sq = strlen(s) - 2;
    for (int i = 0; i < strlen(s) - 1; ++i) {
        x += a[sq--] * powf(10, i);
    }
    id *= n;
    a[0] = 1;
    while (n--) {
        for (int j = 0; j < di; ++j) {
            t = a[j] * x + num;
            a[j] = t % 10;
            num = t / 10;
        }
        while (num) {
            a[di++] = num % 10;
            num /= 10;
        }
    }
    int j = 1;
    if (di <= id) {
        cout << ".";
        for (int i = 0; i < id - di; ++i) {
            cout << "0";
        }
    }
    int hhh=0;
    for (int i = 0; i < di-1; ++i) {
        if(a[i]==0){
            hhh++;
        }
        else break;
    }
    for (int i = di - 1; i >= hhh+0; --i) {

        if (j == di - id + 1) {
            cout << ".";
        }
        j++;
        cout << a[i];
    }
    cout << endl;

}
    return 0;
}


  • 写回答

1条回答 默认 最新

  • 加油吧,小杜 2022-09-26 17:29
    关注

    img

    你这个输入应该是&s啊

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 9月28日
  • 创建了问题 9月26日

悬赏问题

  • ¥30 为什么会失败呢,该如何调整
  • ¥50 如何在不能联网影子模式下的电脑解决usb锁
  • ¥20 服务器redhat5.8网络问题
  • ¥15 如何利用c++ MFC绘制复杂网络多层图
  • ¥20 要做柴油机燃烧室优化 需要保持压缩比不变 请问怎么用AVL fire ESE软件里面的 compensation volume 来使用补偿体积来保持压缩比不变
  • ¥15 python螺旋图像
  • ¥15 算能的sail库的运用
  • ¥15 'Content-Type': 'application/x-www-form-urlencoded' 请教 这种post请求参数,该如何填写??重点是下面那个冒号啊
  • ¥15 找代写python里的jango设计在线书店
  • ¥15 请教如何关于Msg文件解析