| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 701 人关注过本帖
标题:浙大的2个特easy的acm<代码见1楼8楼>
取消只看楼主 加入收藏
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
结帖率:99.76%
收藏
已结贴  问题点数:20 回复次数:6 
浙大的2个特easy的acm<代码见1楼8楼>
程序代码:
#include<stdio.h>

int main(void)
{
    int i=2,j=0,k;
    double aa[10];
    double ff=0.0;
    while (scanf("%lf",&aa[j]))
    {
        if(aa[j]<=0.0000001) break;
        j++;
    }
    k=j;
    j=0;
    while(j<k)
    {
        if(aa[j]<0.5) {printf("%d card(s)\n",1);  j++;ff=0.0;i=2;continue;}
        ff+=(double)1.0/i;
        if(ff>=aa[j]) {printf("%d card(s)\n",i-1);j++;i=2;ff=0.0;continue;}
        i++;
    }

    return 0;
}


[ 本帖最后由 wp231957 于 2012-12-7 21:50 编辑 ]
搜索更多相关主题的帖子: 浙大 
2012-12-07 13:00
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
4楼的小兄弟都开口了 我就都给他了

DO IT YOURSELF !
2012-12-07 13:27
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
程序代码:
#include <stdio.h>
#define max 100
int i=0;
void dec2yyy(int yyy,int source,char* bin)
{
    if(source==0) return;
    dec2yyy(yyy,source/yyy,bin);
    if((source%yyy)<10) bin[i]=(char)(source%yyy+0x30);
    else bin[i]=(char)(source%yyy+0x37);
    i++;
}
int main(void)
{
    char s[max];
    int j=0,k,k1,k2,len=0;
    int flag=1;  
    int flag2=0; 
    int ss[20];
    char* begin=s;
    char* tmp=s;
    char* end=NULL;
    int pan[21]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    for(j=0;j<max;j++) s[j]='\0';
    j=0;
    while (scanf("%d",&ss[j]))
    {
        if(ss[j]==0) break;
        j++;
    }
    k=j;
    int jj=0;
    int p=0;
    while(ss[jj]!=0)
    {
        for(k=2;k<=16;k++)
        {
            dec2yyy(k,ss[jj],s);    
            for(k1=0;k1<max;k1++)  
            {
                if(s[k1]=='\0')
                {
                    end=begin+len-1;
                    break;
                }
                len++;
            }
            if(begin==end){flag=1;goto _next;}
            while(begin!=end)  
            {
                if((end-begin==1) && (*begin==*end)) {flag=1;break;}  
                if(*begin!=*end)
                {
                    flag=0;
                    break;
                }
                else
                {
                    begin++;
                    end--;
                }
            }
_next:
            if(flag==1)   
            {
                pan[p++]=k;
                flag2++;
            }
            for(j=0;j<max;j++) {s[j]='\0';i=0;}  
            len=0;
            flag=1;
            begin=tmp;
        }
        if(flag2>0)
        {
            printf("Number %d is palindrom in basis",ss[jj]);
            k2=0;
            while(pan[k2]!=0){printf(" %d",pan[k2]);k2++;}
            printf("\n");
        }
        for(k2=0;k2<15;) pan[k2++]=0;
        if(flag2<1) printf("Number %d is not a palindrom\n",ss[jj]);
        flag2=0;
        jj++;
        p=0;
    }
    return 0;
}


[ 本帖最后由 wp231957 于 2012-12-7 21:45 编辑 ]

DO IT YOURSELF !
2012-12-07 16:30
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
程序代码:
F:\c_source\t2\Debug>fc
1
2
3
11
12
13
0
Number  1 is palindrom in basis 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Number  2 is palindrom in basis 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Number  3 is palindrom in basis 2 4 5 6 7 8 9 10 11 12 13 14 15 16
Number 11 is palindrom in basis 10 12 13 14 15 16
Number 12 is palindrom in basis 5 11 13 14 15 16
Number 13 is palindrom in basis 3 12 14 15 16
这是我的输出
提交显示Presentation Error  百度之  貌似是输出格式有问题

DO IT YOURSELF !
2012-12-07 19:44
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
题目如下:
程序代码:
Statement of the Problem
We say that a number is a palindrom if it is the sane when read from left to right or from right to left. For example, the number 75457 is a palindrom.

Of course, the property depends on the basis in which is number is represented. The number 17 is not a palindrom in base 10, but its representation in base 2 (10001) is a palindrom.

The objective of this problem is to verify if a set of given numbers are palindroms in any basis from 2 to 16.



Input Format

Several integer numbers comprise the input. Each number 0 < n < 50000 is given in decimal basis in a separate line. The input ends with a zero.



Output Format

Your program must print the message Number i is palindrom in basis where I is the given number, followed by the basis where the representation of the number is a palindrom. If the number is not a palindrom in any basis between 2 and 16, your program must print the message Number i is not palindrom.



Sample Input

17
19
0



Sample Output

Number 17 is palindrom in basis 2 4 16
Number 19 is not a palindrom




DO IT YOURSELF !
2012-12-07 19:44
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
以下是引用beyondyf在2012-12-7 21:09:29的发言:

下面这几行的问题,你在最后一个数据末尾也多加了一个空格
            printf("Number %d is palindrom in basis ",ss[jj]);
            k2=0;
            while(pan[k2]!=0){printf("%d ",pan[k2]);k2++;}
            printf("\n");
可以这样改改,注意printf中的空格位置

            printf("Number %d is palindrom in basis",ss[jj]);
            k2=0;
            while(pan[k2]!=0){printf(" %d",pan[k2]);k2++;}
            printf("\n");
还是杨兄弟厉害   终于yes了
图片附件: 游客没有浏览图片的权限,请 登录注册

DO IT YOURSELF !
2012-12-07 21:38
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
还是功力不够深厚啊
这么一个多重进制回文数的问题,我8楼的代码虽然acm过了
但是,还是感觉自己写的太乱  变量用的太多了,我自己都记不得哪个变量是干什么的了

那个acm还不允许有注释,晕

DO IT YOURSELF !
2012-12-07 21:45
快速回复:浙大的2个特easy的acm<代码见1楼8楼>
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027890 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved