My coding way (7)

本博客讨论了如何判断一个整数在特定进制下是否为回文数,涉及了整数转换、字符串操作及回文数的定义。

问题 F: 回文数

时间限制: 1 Sec  内存限制: 128 MB

题目描述

如果一个数从左边读和从右边读一样,那么我们说这是一个回文数。

例如,75457是一个回文数。当然,数的这个特性还依赖于表示它的进制。如果用十进制表示17,它不是回文数;但是如果用二进制(10001)表示它,它就是一个回文数。

本题的目标是,输入一个整数n和它的进制d,判断整数nd进制下是否为回文数。

输入

第一行输入一个数 T 表示有 T 组测试数据。

接下来的T行,每行两个数,分别是整数 n 和进制 d

输出

若是回文数,则输出"Number'n'is palindromein basis 'd'"(不包括引号),若不是回文数,则输出"Number 'n' is not palindrome inbasis 'd'"(不包括引号)。

样例输入

2

17 2

19 4

样例输出

Number 17 is palindromein basis 2

Number 19 is notpalindrome in basis 4

 

T_T 什么都不说了,最开始做的时候思路完全错了,直接导致Error


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char buff[128];
void deal()
{
    int dec,binary;
    scanf("%d %d",&dec,&binary);
    int orgdec=dec;
    memset(buff,0,128);
    int i=0;
    while(dec>=binary)
    {
        buff[i++]='0'+dec%binary;
        dec=dec/binary;
    }
    buff[i]='0'+dec;
    int len=strlen(buff);
    int slen=len/2;
#ifndef __GNUC__
    printf("%s\n",buff);
#endif
    for(i=0;i<slen;i++)
    {
        if(buff[i]!=buff[len-i-1])
        {
            printf("Number %d is not palindrome in basis %d\n",orgdec,binary);
            return;
        }
    }
    printf("Number %d is palindrome in basis %d\n",orgdec,binary);
}
int main()
{
    int all;
    scanf("%d",&all);
    for(;all>0;all--)
    {
        deal();
    }
    return 0;
}


Currently You are now a website builder. These are the code in my cart.php & functions.php. Currently, i am very satisfied with my layout. However, I want to achieve cart like Shopee / Taobao / Lazada, that allow my customer to 1) Do selective checkout, where only selected items are sent to checkout page, and after order created, only these items will be removed from cart. On the other side, non-selected items are retained inside cart, until customer remove them manually through 清除購物車 / 移除選中商品 or customer check out them. Only remove when order is created. If customer go back from checkout page or payment page, or anything, as long as order is not created, dont remove them. Currently im using restore cart way to achieve this, but everything from cart is removed currently after order created. theres some mistake that stop me from achieving this. I turned on feature where customer can see how many items are inside cart through the cart icon at header. At the same time, i dont want my customer to notice that their cart is cleared and recovered before (the amount of items in cart icon will show 0 when havent recover and the number of items after recover). I dont want them to notice the change, therefore, we have to recover it fast until customer did not notice them. Please be considerate regarding customer that use PC because they might access my website through another tab, at there, they can see the amount of items in cart icon. Therefore, i want it to always show the correct amount, only remove when the order is created and maintain if the order is not created. I dont want them to notice how it works (recovering) 2) All these 全选 刪除選中的商品 清空購物車 输入优惠券代码 应用优惠券 已选商品: 0 件,共计: RM0.00 结算 works perfectly fine, please remain them. Maintaining all the layout and achieved functions. Please check which part stopped me from achieving the selective checkout (maintain non-selected items inside cart, only remove selected to checkout items when order created, and dont let customer nmotice the change in their cart. I want them to no matter access from where, either new tab, other device etc, they will see the correct items in their cart) For now, If i cancel the payment halfway, i am logged out when back from payment page, and when i check from other tab, non-selected items are removed from cart, only selected items are still inside cart. Also, when i login back after payment page, it redirects me to pay-only page. Please refer how taobao cart works, and review which part is stopping me from achieve taobao cart, give me the part of code to be changed and the new code to replaced with the current one, as i have no coding basic
最新发布
08-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值