/ 21班 /

记录详情

Accepted

/in/foo.cc: In function 'std::__cxx11::string jz(long long int)':
/in/foo.cc:18:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ret.size();i++)
                 ~^~~~~~~~~~~
/in/foo.cc: In function 'bool hw2(std::__cxx11::string)':
/in/foo.cc:38:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0,j=s.size()-1;i<s.size();i++,j--)
                              ~^~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 1ms 428.0 KiB
#2 Accepted 2ms 1008.0 KiB
#3 Accepted 2ms 360.0 KiB
#4 Accepted 2ms 420.0 KiB
#5 Accepted 2ms 356.0 KiB
#6 Accepted 3ms 352.0 KiB
#7 Accepted 4ms 384.0 KiB
#8 Accepted 7ms 340.0 KiB
#9 Accepted 12ms 328.0 KiB
#10 Accepted 1ms 352.0 KiB

代码

#include<bits/stdc++.h>
#define int long long 
using namespace std;
int n;
string jz(int n)
{
    string ret="";
    while(n)
    {
        ret+='0'+n%2;
        n/=2;
    }
    string t=ret;
    for(int i=t.size()-1;i>=0;i--)
    {
        ret[t.size()-1-i]=t[i];
    }
    for(int i=0;i<ret.size();i++)
    {
        if(ret[i]=='1')break;
        ret[i]=0;
    }
    return ret;
}
bool hw1(int a)
{
    if(a<10)return 1;
    int t=a,s=0;
    while(a)
    {
        s=s*10+a%10;
        a/=10;
    }
    return (s==t);
}
bool hw2(string s)
{
    for(int i=0,j=s.size()-1;i<s.size();i++,j--)
    {
        if(s[i]!=s[j])
            return false; 
    }
    return true;
}
signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string t=jz(i);
        if(hw1(i)&&hw2(t))
        {
            cout<<i<<':'<<t<<endl;
        }
    }
    return 0;
}

信息

递交者
类型
递交
题目
P1029 双进制回文数
题目数据
下载
语言
C++
递交时间
2023-12-09 12:59:43
评测时间
2023-12-09 12:59:43
评测机
分数
100
总耗时
41ms
峰值内存
1008.0 KiB