1.E : 构造回文串

Time Limit: 1 Sec Memory Limit: 128 Mb


Description

给你一个整型(int)数N,可以将其看成字符串,是否有可能在N前加入若干个0(也可以不加),使得该字符串为回文串。

Input

数字N

0 ≤ N ≤ 10^9

Output

若可以则输出Yes,不可以则输出No,输出结束要换行。

Sample Input

1210

Sample Output

Yes

代码实现

#include <stdio.h>

/*
    1.因为可以补零,反其道而行之,则是把末尾的零去掉
    2.n最大为10^9,定义一个长度为9的数组来存储每位数字
*/

int main()
{
    int n;
    scanf("%d", &n);
    while (n % 10 == 0)
    {
        n /= 10;//去掉末尾的0
    }
    int* a = new int[9];
    int i = 0;
    while (n / 10 != 0)
    {
        a[i++] = n % 10;
        n /= 10;
    }
    a[i] = n;
    int k = 0;
    int flag = 1;
    for (int j = 0; j <= i / 2; j++)
    {
        if (a[j] != a[i - k])//前后比较
        {
            flag = 0;
            break;
        }
        k++;
    }
    if (!flag)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Exception in Application constructor Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:893) Caused by: java.lang.RuntimeException: Unable to construct Application instance: class Main at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:750) Caused by: java.lang.NoSuchMethodException: Main.<init>() at java.lang.Class.getConstructor0(Class.java:3110) at java.lang.Class.getConstructor(Class.java:1853) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$7(LauncherImpl.java:818) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$3(WinApplication.java:177) ... 1 more出现这个报错怎么解决
05-26

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值