程序超时求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;
}
}
}

可以出结果,加上
#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");

}

改成scanf和printf试试


可以的,唯一跟你的区别是你没有#include <iostream>,我没有用#include<bits/stdc++.h>

这个回答系统真的是bug太多,编辑结果上不去和编辑结果不一样啊!
如有帮助,望采纳!

这不是我的代码吗,@weixin_53577834


 
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
scanf("%d%d", &n,&k);
long long total=1;
for(int i=1;i<=k;i++)
{
    total*=n;
}
if(total<1000)cout<<total<<endl;
else printf("%03d\n",total%1000);
return 0;
}

#include<iostream>
using namespace std;
int main()
{
    long long x, n;
    cin >> x >> n;
    long long total = x;
    int i = 1;
    for (; i < n; i = i*2)
    {
        total *= total;
 
    }
    if (i > n)
    {
        for (int j = n; j < i; j++)
            total = total / x;
    }
    int a = total % 1000;
    //total%1000=000
    if (total<1000)
    {
        cout << total;
    }
    else
    {
        if (a<10)
        {
            cout << "00" << a;
        }
        //total%1000=010
        else if (a<100)
        {
            cout << "0" << a;
        }
        //total%1000=001
        else
        {
            cout << a;
        }
    }
    system("pause");
 
}

题主试试这个:

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

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
scanf("%d%d", &n,&k);
long long total=1;
for(int i=1;i<=k;i++)
{
    total*=n;
}
if(total<1000)cout<<total;
else printf("%03d\n",total%1000);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
scanf("%d%d", &n,&k);
long long total=1;
for(int i=1;i<=k;i++)
{
    total*=n;
}
if(total<1000)cout<<total<<endl;
else printf("%03d\n",total%1000);
return 0;
}


这个这个这个