ZOJ 简单题集合

这部分题由于过于简单,属于白送题目,因此把所有特别简单题的合集于此。

1048:统计某人12个月的银行帐户余额的平均数。(简单的令人汗!)

Code_1048
/*ZOJ 1048: 统计小数的平均数!居然就是12个double求平均数。。汗!*/
#include <stdio.h>
double balance[12];
int main()
{
 int i;
 double sum=0,aver;
 for(i=0;i<12;i++)
 {
  scanf("%lf", &balance[i]);
  sum+=balance[i];
 }
 aver=sum/12;
 printf("$%.2lf", aver);
}

 1070:简单交流电路,求电阻上的电压降落。纯属解数学方程。

Code_1070
/*1070 ZOJ*/
#include <stdio.h>
#include <math.h>
void main()
{
    double vs,vr,r,c,w;
    int n,i;
    while(scanf("%lf %lf %lf %d", &vs,&r,&c, &n)!=EOF && n>0)
    {
        for(i=0;i<n;i++)
        {
            scanf("%lf",&w);
            vr=w*c*vs/sqrt(w*w+1);
            printf("%.3lf\n", vr);
        }
    }
}

 1049:某人买地,给出一点坐标,流失土地以半圆形扩张,每年增加50平方英里面积。问多少年后某点消失。

Code_1049
/*ZOL 1049 - I Think I Need a Houseboat. */
#include <math.h>
#include <stdio.h>
/*0.01 PI*/
#define PI_PERCENT 0.03141592653589793

int main()
{
    int i,n,years;
    double x,y;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lf %lf",&x,&y);
        years=(int)((x*x+y*y)*PI_PERCENT)+1;
        printf("Property %d: This property will begin eroding in year %d.\n", i, years);        
    }
    printf("END OF OUTPUT.");
    return 0;
}

1078:求一个数字用2,3,...,16进制表示时是否是“回文数”,例如12321。

Code_1078
/*1078 - Palindrom Numbers (回文数字)*/
#include <string.h>
#include <stdio.h>
/*判断一个数字n在以base为进制时是否是回文数字*/
int IsPalindrom(unsigned int n, unsigned int base)
{
    int i=0,j;
    char buffer[20],*s;
    memset(buffer,0,sizeof(buffer));
    while(n)
    {
        buffer[i++]=n%base;
        n/=base;
    }
    /*现在i就是strlen(buffer),判断是否回文数*/
    s=buffer;
    for(j=0;j<i/2;j++)
        if(buffer[j]!=buffer[i-1-j])
            return 0;
    /*说明是回文数*/
    return 1;
}

int main()
{
    unsigned int n, base;
    char text[64];
    while(scanf("%d",&n)!=EOF && n>0)
    {
        memset(text,0,sizeof(text));
        for(base=2;base<=16;base++)
        {
            if(IsPalindrom(n, base))
                sprintf(text+strlen(text)," %d",base);
        }
        if(strlen(text)>0)
            printf("Number %u is palindrom in basis%s\n", n, text);
        else
            printf("Number %u is not a palindrom\n", n);
    }
    return 0;
}

1099:简单的HTML解析。仅包含<br>,<hr>标记。每行80字符。

Code_1099
/*ZOJ 1099 - HTML */
#include <stdio.h>
#include <string.h>
int main()
{
    int i,length=0;/*当前行的长度*/
    char word[81];
    while(scanf("%s", word)!=EOF)
    {
        if(strcmp(word, "<br>")==0)
        {
            printf("\n");
            length=0;
        }
        else if(strcmp(word, "<hr>")==0)
        {
            if(length>0) printf("\n");
            for(i=0;i<80;i++) printf("-");
            printf("\n");
            length=0;
        }
        else if(length+strlen(word)+1 >80)
        {
            /*需要换行*/
            printf("\n%s", word);
            length=strlen(word);
        }
        else
        {
            /*无需要换行*/
            if(length>0)
            {
                printf(" ");
                length++;
            }
            printf("%s", word);
            length += strlen(word);
        }
    }
    return 0;
}

1180:要求求出100w以内的所有Self Number。所谓SelfNumber,即不存在任何数字n,使n+digitsum(n)=m成立,则m称为SelfNumber。这题我写的很“暴力”,开了100w字节空间,并且要计算100w次才能得出结果。运行时间长达50ms。

Code_1180
/*ZOJ 1180 - Self Numbers */
#include <stdio.h>
#define N 1000001
char flag[N]; /*如果i是self Number,则flag[i]=0*/

unsigned long d(unsigned long n)
{
     unsigned long result=n;
    while(n)
    {
        result+=n%10;
        n/=10;
    }
    return result;
}

void InitFlags()
{
    unsigned long i,j;
    for(i=1;i<N;i++)
    {
        j=d(i);
        flag[j]=1;
    }
}

int main()
{
    unsigned long i;
    InitFlags();
    for(i=1;i<N;i++)
        if(flag[i]==0)
            printf("%u\n",i);
    return 0;
}

1241:给出直角三角形的三条边a,b,c其中的两个,求另外一个。 

Code_1241
/*1241 - Geometry Made Simple 很简单的题*/
#include <math.h>
#include <stdio.h>
int main()
{
    int a,b,c,count=1;
    while(1)
    {
        scanf("%d %d %d", &a, &b, &c);
        if(a==0 && b==0 && c==0) break;
        
        printf("Triangle #%d\n", count++);
        
        if(c==-1)
            printf("c = %.3f\n", sqrt(a*a+b*b));
        else if(a==-1)
        {
            if(c<=b) printf("Impossible.\n");
            else printf("a = %.3f\n", sqrt(c*c-b*b));
        }
        else if(b==-1)
        {
            if(c<=a) printf("Impossible.\n");
            else printf("b = %.3f\n", sqrt(c*c-a*a));
        }
        
        printf("\n");
    }
}

1242:用C14衰减法测量生物年代。生物体存活时,C14含量为810 d/(克*小时),死亡后该值每5730年衰减至原来的一半。现在给出生物体样本重量,C14含量,求出生物生活年代。对于10000年以下的,四舍五入到100年整数倍,对于10000年以上的,四舍五入到1000年整数倍。

假设当前含量为 a d/(克*小时),年代为t,则有方程:t/5370=log2(810/a);

因此有:t=5370*log2(810/a);

库函数中只有自然对数和10为底对数,可根据对数性质:log2(x)=log(x)/log(2);

四舍五入可以根据(加0.5然后取整)法。

Code_1242
#include <math.h>
#include <stdio.h>
int main()
{
    int x1,x2,n=1;
    unsigned long result;
    double years;
    while(scanf("%d %d",&x1,&x2)!=EOF)
    {
        if(x1==0 && x2==0) break;
        //log2(x)=log(x)/log(2), log是自然对数,以e为底
        years = log(810.0/x2*x1)*5730/log(2);
        if(years<10000)
        {
            //四舍五入到100整数倍
            result = ((unsigned long)((years+50)/100))*100;
        }
        else
        {
            //四舍五入到1000整数倍
            result = ((unsigned long)((years+500)/1000))*1000;
        }
        printf("Sample #%d\n", n++);
        printf("The approximate age is %lu years.\n\n", result);
    }
    return 0;
}

1243:URL字符串解析。提取出协议,主机地址,端口号,服务器路径。

Code_1243
/*ZOJ 1243 - URLs*/
#include <string.h>
#include <stdio.h>
/*读取URL的缓冲区*/
char line[64];
int main()
{
    int n, i, j, hoststart;
    char *s,c;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%s", line);
        printf("URL #%d\n", i);
        /*<protocol> is always one of http, ftp, gopher*/
        switch(line[0])
        {
            case 'h': hoststart=7; printf("Protocol = http\n");break;
            case 'f': hoststart=6; printf("Protocol = ftp\n");break;
            case 'g': hoststart=9; printf("Protocol = gopher\n");break;
        }
        
        /*<host> 由字母/数字,点组成 */
        printf("Host     = "); /*acm.baylor.edu*/
        for(j=hoststart; line[j]!=':' && line[j]!='/' && line[j]; j++) printf("%c", line[j]);
        printf("\n");
        
        /*[Port]*/
        printf("Port     = ");
        if(line[j]==':')
        {
            for(j=j+1; line[j]!='/' && line[j]; j++) printf("%c", line[j]);
            printf("\n");
        }
        else
            printf("<default>\n");
        
        /*Path,如果line[j]为斜杠则说明有Path*/
        printf("Path     = ");
        if(line[j]=='/')
        {
            for(j=j+1; line[j]; j++) printf("%c", line[j]);
            printf("\n");
        }
        else
            printf("<default>\n");
        
        /*blank line after each test cas.*/
        printf("\n");
    }
    return 0;
}

1334:一个计算器,把某进制数转换成另一个进制。

Code_1334
/* ZOJ 1334 - Basically Speaking */
/* 一个计算器,把某进制数转换成另一个进制 */
#include <stdio.h>
#include <string.h>

char numbers[]="0123456789ABCDEF";

/*把输入字符串,以进制转换到dest */
void Convert(unsigned long n, char *dest, int base)
{
    int index=6;
    strcpy(dest, "       ");
    while(n)
    {
        if(index<0)
        {
            strcpy(dest,"  ERROR");/*注意右对齐!因此前面补齐2个空格!*/
            return;
        }
        dest[index--]=numbers[n%base];
        n/=base;
    }
}

/*把输入的字符串(某进制)转换为一个整数*/
unsigned long GetNumber(char *src, int base)
{
    unsigned long n=0, k=1;
    int i;
    for(i=strlen(src)-1; i>=0; i--)
    {
        n+=(strchr(numbers, src[i]) - numbers )*k;
        k*=base;
    }
    return n;
}

int main()
{
    char buffer[100], result[8];
    unsigned long n;
    int base1,base2;
    while(scanf("%s %d %d", buffer,&base1,&base2)!=EOF)
    {
        n=GetNumber(buffer, base1);
        Convert(n, result, base2);
        printf("%s\n", result);
    }
    return 0;
}

1760:输入一序列数字(以0表示结束),输出这些数字中有多少个二倍关系。

Code_1760
/*ZOJ 1760 - Doubles*/
/*寻找一个输入序列(2~15个整数)中有多少二倍关系*/
#include <stdio.h>
int n[16]; /*存储序列数字*/
int count; /*该List中含有多少个数字*/
int main()
{
    int i,j,result;
    while(1)
    {
        scanf("%d",&n[0]);
        if(n[0]==-1) break; /*检查第一个数字是不是-1,表示结束输入*/
        count=1;
        for(count=1;count<16 && n[count-1]!=0; count++)
             scanf("%d", &n[count]);
        
        /*统计二倍的个数*/
        result=0;
        for(i=0;i<count-1;i++)
            for(j=i+1;j<count;j++)
                if((n[i]==n[j]*2)||(n[j]==n[i]*2))
                    result++;
        printf("%d\n",result); 
    }
    return 0;
}

1763:好像是求取一些连续输入的温度的差值。

Code_1763
#include <stdio.h>
int main()
{
    double t1=0,t2=0;
    scanf("%lf",&t1);
    while(scanf("%lf",&t2)!=EOF && ((int)t2) < 999)
    {
        printf("%.2lf\n",t2-t1);
        t1=t2;
    }
    printf("End of Output\n");
    
}

2001:给出两个数字,颠倒数位后想加,结果再颠倒数位。例如输入24 1,则42+1=43, 输出34;

Code_2002
/* ZOJ 2002 - Adding Reversed Numbers */
#include <stdio.h>
int GetInverseNum(int n)
{
    int r=0;
    while(n)
    {
        r=r*10+(n%10);
        n/=10;
    }
    return r;
}

int main()
{
    int count,i,n1,n2,sum;
    scanf("%d", &count);
    for(i=0;i<count;i++)
    {
        scanf("%d %d", &n1,&n2);
        n1=GetInverseNum(n1);
        n2=GetInverseNum(n2);
        sum=GetInverseNum(n1+n2);
        printf("%d\n",sum);
    }
    return 0;
}

2987:给出n组输入,每个输入包含一个数字m(以1为base),和一个单词,打印出该单词去掉第m个字母的结果。

Code_2987
/* ZOJ 2987 - Misspelling */
#include <stdio.h>
#include <string.h>
char line[84];
int main()
{
    int n, m, i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        /*m是以1为base的,表示要删除第几个字符*/
        scanf("%d %s",&m, line);
        printf("%d ", i);/*打印序号*/
        /*注意不要打印索引为m-1的字符即可!*/
        for(j=0;j<m-1;j++) printf("%c", line[j]);
        for(j=m;j<strlen(line);j++) printf("%c", line[j]);
        printf("\n");
    }
    return 0;
}

 ( TO BE CONTINUED... )        --hoodlum1980

        

时间: 2024-07-31 06:11:25

ZOJ 简单题集合的相关文章

ZOJ 简单题集合(二)

对以下简单题,我同时给出一个我主观认为的难度值(0.1~1.0之间). (1). ZOJ 1072: Microprocessor Simulation. (Difficulty: 0.2) http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1072 微处理器模拟,它含有两个累加器,代码和内存统一寻址,即冯诺依曼结构,比较简单. ZOJ1072_cpp #include <stdio.h>#include <stri

ZOJ 简单题集合(四)

(1)ZOJ 1016. Parencodings 题意:把一个括号表达式 S,从 P 编码转换为 W 编码. P 编码:P = P1,P2, ... , Pn; 其中 Pi  是 S 的第 i 个右括号前面的左括号个数. W 编码:W = W1, W2, ... , Wn; 对于 S 中的某一个右括号 a,Wi 是从与 a 匹配的左括号开始数起,数到 a 为止的右括号个数.   例如:S (((()()())))P-编码: 4 5 6 6 6 6:W-编码: 1 1 1 4 5 6:   分析

c语言编程-关于C语言字符串的简单题求助

问题描述 关于C语言字符串的简单题求助 进行对输入的字符串重新排列,要求字母在前,数字在后,并不改变字母和数字之间的字符排列顺序. 解决方案 #include void main() { char a[10] = {0}, b[10] = {0}, c[10]={0}; int n = 0, m = 0, k = 0,f = 0; printf("输入字符串:"); gets(a); for(int j = 0; j < 10; j++) { if((a[j] >= 'a'

源代码-求大神,ZOJ 1002题怎么老出错

问题描述 求大神,ZOJ 1002题怎么老出错 题目链接http://acm.zju.edu.cn/onlinejudge/showRuns.do?contestId=1 提交结果老是的回复是 wrong answer. 样本输入输出都正确. 我提交是用C++提交的,这个应该不成问题 求大神指点. C语言 以下是我提交的源代码 #include"stdio.h" #define N 6 char net[N][N];//最大存储数据容量 int MAX,max;//MAX为最终最大值,

多家地方电视台播猜谜节目简单题骗高话费

新京报制图/丁华勇吉林卫视播出的电视猜谜节目.青海卫视播出的电视猜谜节目. 一边是高额现金大奖,一边是简单得看一眼就能知道答案的猜谜题目.近来,此类有奖竞猜节目出现在不少电视台的清晨和午夜时段,丰厚的奖项,加上主持人"快拿起电话,5000元大奖就是你的."的诱惑,吸引不少观众参与.但真正打过电话的人,都大呼"上当". 6月29日凌晨1时30分许,几家地方卫视频道不约而同的播出电视猜谜节目."什么酒需要两个人一起喝?"节目中不断有语音提示"

HDOJ 1326 Box of Bricks(简单题)

Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. Look, I've built a wall!'', he tells his older sister Alice.Nah, you should make all stacks the same heigh

HDOJ 1323 Perfection(简单题)

Problem Description From the article Number Theory in the 1994 Microsoft Encarta: "If a, b, c are integers such that a = bc, a is called a multiple of b or of c, and b or c is called a divisor or factor of a. If c is not 1/-1, b is called a proper di

HDOJ/HDU 2568 前进(简单题)

Problem Description 轻松通过墓碑,进入古墓后,才发现里面别有洞天. 突然,Yifenfei发现自己周围是黑压压的一群蝙蝠,个个扇动翅膀正准备一起向他发起进攻! 形势十分危急! 好在此时的yifenfei已经不是以前那个经常被lemon抢走MM的菜鸟了!面对众多蝙蝠的嗜血狂攻,只见yifenfei使出轻灵的剑法,刷,刷,刷,瞬间搞定-- 现已知yifenfei使用了2招(剑招A和剑招B):剑招A,一招能杀死一半的蝙蝠.但是如果当前的蝙蝠数为奇数,那么就必须先出一招剑招B杀死其中

HDOJ(HDU) 2123 An easy problem(简单题...)

Problem Description In this problem you need to make a multiply table of N * N ,just like the sample out. The element in the ith row and jth column should be the product(乘积) of i and j. Input The first line of input is an integer C which indicate the