社区讨论

运行时间要281ms,太长了,求改进建议

P1035[NOIP 2002 普及组] 级数求和参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@m40zi0m9
此快照首次捕获于
2024/11/28 15:19
去年
此快照最后确认于
2024/11/28 15:35
去年
查看原帖
CPP
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n,x;
    int counter = 0;
    string helper;
    cin>>n>>x;
    for (int i = 1; i<n+1; i++){
//        cout<<i<<endl;
        helper = to_string(i);
//        cout<<helper<<endl;
        for (int j = 0; j<helper.length(); j++){
            if (helper[j] - '0' == x){
                counter += 1;
//                cout<<helper<<endl;
//                cout<<counter<<endl;
            }
        }
    }
    cout<<counter<<endl;
}

回复

1 条回复,欢迎继续交流。

正在加载回复...