标题:浙大的2个特easy的acm<代码见1楼8楼>
只看楼主
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
结帖率:99.76%
已结贴  问题点数:20 回复次数:13 
浙大的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
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
得分:0 
恭喜楼主
2012-12-07 13:01
阿鞠尼
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:首尔
等 级:蒙面侠
威 望:5
帖 子:1467
专家分:4442
注 册:2012-5-30
得分:0 
恭喜恭喜

喜欢睡觉 却经常熬夜
2012-12-07 13:14
阿鞠尼
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:首尔
等 级:蒙面侠
威 望:5
帖 子:1467
专家分:4442
注 册:2012-5-30
得分:20 
二位都是c版的版主了 分就给我吧

喜欢睡觉 却经常熬夜
2012-12-07 13:15
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
得分:0 
已结贴。。。。


[fly]存在即是合理[/fly]
2012-12-07 13:26
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:0 
4楼的小兄弟都开口了 我就都给他了

DO IT YOURSELF !
2012-12-07 13:27
阿鞠尼
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:首尔
等 级:蒙面侠
威 望:5
帖 子:1467
专家分:4442
注 册:2012-5-30
得分:0 
回复 6楼 wp231957
感谢老大

喜欢睡觉 却经常熬夜
2012-12-07 14:06
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册: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: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册: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: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册: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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-390002-1-1.html




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

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