写代码好难1q1q 2022-01-28 14:07 采纳率: 100%
浏览 2
已结题

这两个代码哪里不一样啊,运算不一样,我哭

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PII;
const int N=3010;
int a[N];
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin>>n;

for(int i=1; i<=n; i++)
{
    int x=i;
    int cnt=0;

    while(1)
    {
        int num=0;
        if(x==0) break;
        if(x<10)
        {
            x=0;
            cnt++;
        }
        else
        {
            int y=x;
            while(y)
            {
                num+=y%10;
                y/=10;
            }
            cnt++;
        }
        x=num;
    }
    a[i]=cnt;
}
int res=0;
for(int i=1; i<=n; i++)
{
    for(int j=i+1; j<=n; j++)
    {
        for(int k=j+1; k<=n; k++)
        {
            if(a[i]<a[j]&&a[j]<a[k])
            {
                res++;
            }
        }
    }
}
cout<<res<<endl;
return 0;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PII;

const int N = 3010;

int a[N];

int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;

for (int i = 1; i <= n; i ++)  // 预处理
{
    int x = i;
    int cnt = 0;
    while (1)
    {
        int num = 0;
        if (x == 0)
            break;
        if(x < 10)
        {
            x = 0;
            cnt ++;
        }
        else
        {
            int y = x;
            while (y)
            {
                num += y % 10;
                y /= 10;
            }
            cnt ++;
        }
        x = num;
    }
    a[i] = cnt;
}
int res = 0;
for (int z = 1; z <= n; z ++) // 暴力查找
    for (int y = z + 1; y <= n; y ++)
        for (int x = y + 1; x <= n; x ++)
            if (a[x] < a[y] && a[y] < a[z])
                res ++;

cout << res << endl;

return 0;

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

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

    悬赏问题

    • ¥15 气象网格数据与卫星轨道数据如何匹配
    • ¥15 VS target framework下拉菜单中不显示(语言-c#|开发工具-visualstudio)
    • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
    • ¥15 微软账户问题不小心注销了好像
    • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
    • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
    • ¥20 关于web前端如何播放二次加密m3u8视频的问题
    • ¥15 使用百度地图api 位置函数报错?
    • ¥15 metamask如何添加TRON自定义网络
    • ¥66 关于川崎机器人调速问题