weixin_53577834 2021-08-29 16:25 采纳率: 43.5%
浏览 160
已结题

程序超时求zhu。好像是不能用cin和cout

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long x,n;
long long total=1;
cin>>x>>n;
for(int i=1;i<=n;i++)
{
total*=x;
}
int a=total%1000;
//total%1000=000
if(total<1000)
{
cout<<total;
}
else
{
if(a==0)
{
cout<<"000";
}
//total%1000=001
else if(a!=0&&a<10)
{
cout<<"00"<<a;
}
//total%1000=010
else if(a>9&&a<100)
{
cout<<"0"<<a;
}
//total%1000=001
else
{
cout<<a;
}
}
}

  • 写回答

10条回答 默认 最新

  • 急速光粒 2021-08-29 16:35
    关注

    可以出结果,加上
    #include
    最后加上
    system("pause");

    img

    #include<iostream>
    
    using namespace std;
    int main()
    {
        long long x, n;
        long long total = 1;
        cin >> x >> n;
        for (int i = 1; i <= n; i++)
        {
            total *= x;
        }
        int a = total % 1000;
        //total%1000=000
        if (total<1000)
        {
            cout << total;
        }
        else
        {
            if (a == 0)
            {
                cout << "000";
            }
            //total%1000=001
            else if (a != 0 && a<10)
            {
                cout << "00" << a;
            }
            //total%1000=010
            else if (a>9 && a<100)
            {
                cout << "0" << a;
            }
            //total%1000=001
            else
            {
                cout << a;
            }
        }
        system("pause");
    
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(9条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月31日
  • 已采纳回答 8月29日
  • 创建了问题 8月29日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度