C语言练习-洛谷【入门1】顺序结构

 工作需要,最近在重新学习c语言,都忘得差不多了,拿洛谷的题目练练手~感觉挺适合新手的,大家可以参考参考,也可以帮我找找错误QAQ

1、B2002

#include
int main(){
   printf("Hello,World!");
}

2、B2025

#include
int main(){
    printf("  *\n ***\n*****\n ***\n  *\n");
}

3、P1000

#include 
#include 

int main()
{
    printf(
"                ********\n"
"               ************\n"
"               ####....#.\n"
"             #..###.....##....\n"
"             ###.......######              ###            ###\n"
"                ...........               #...#          #...#\n"
"               ##*#######                 #.#.#          #.#.#\n"
"            ####*******######             #.#.#          #.#.#\n"
"           ...#***.****.*###....          #...#          #...#\n"
"           ....**********##.....           ###            ###\n"
"           ....****    *****....\n"
"             ####        ####\n"
"           ######        ######\n"
"##############################################################\n"
"#...#......#.##...#......#.##...#......#.##------------------#\n"
"###########################################------------------#\n"
"#..#....#....##..#....#....##..#....#....#####################\n"
"##########################################    #----------#\n"
"#.....#......##.....#......##.....#......#    #----------#\n"
"##########################################    #----------#\n"
"#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#\n"
"##########################################    ############\n");
    return 0;
}

4、P1001

#include
int main(){
int a,b,c;
scanf("%d %d\n",&a,&b);
c=a+b;
printf("%d\n",c);
return 0;
}

5、P2005

#include
int main(){
   char a;
   scanf("%c",&a);
   printf("  %c\n %c%c%c\n%c%c%c%c%c\n",a,a,a,a,a,a,a,a,a);
}

6、P5703 【深基2.例5】苹果采购

#include
int main(){
  int n,m;
  scanf("%d %d",&n,&m);
  printf("%d\n",n*m);
  return 0;
}

7、P5704 【深基2.例6】字母转换

#include
int main(){
    char c;
    scanf("%c",&c);
    printf("%c",c-32);
    return 0;
}

8、P5705 【深基2.例7】数字反转

#include
#include
int main(){
    char a,b,c,d;
    scanf("%c%c%c.%c",&a,&b,&c,&d);
    printf("%c.%c%c%c",d,c,b,a);
    return 0;
}

9、P5706 【深基2.例8】再分肥宅水

#include
int main(){
    double t,m;
    int n;
    scanf("%lf %d",&t,&n);
    m=t/n*1.0;
    printf("%.3f\n%d",m,2*n);
    return 0;
}

10、P5708 【深基2.习2】三角形面积

#include 
#include 
#include 
#include 
int main()
{
    double a,b,c,p,s;
    scanf("%lf %lf %lf",&a,&b,&c);
    p=(a+b+c)/2;
    s=sqrt(p*(p-a)*(p-b)*(p-c));
    printf("%.1f",s);
    return 0;

}

11、P5707 【深基2.例12】上学迟到

#include 
#include 
#include 
#include 
int main()
{
    int s,v;//路程和速度
    int t;//路上至少需要花费的时间
    int x,y,H,M;//时、分
    scanf("%d %d",&s,&v);
    if(s%v==0){
        t=s/v+10;
 
    }
    else{
        t=s/v+11;
    }
    if(480-t<0){
        x=1440+(480-t);
        H=x/60;
        M=x%60;
    }
    else{
        y=480-t;
        H=y/60;
        M=y%60;
    }
    if(H>=10){
        if(M>=10)printf("%d:%d",H,M);
        else printf("%d:0%d",H,M);
    }else{
        if(M>=10)printf("0%d:%d",H,M);
        else printf("0%d:0%d",H,M);
    }
    return 0;

}

12、B2029 大象喝水

这道题目我写的有些问题,先暂时放上来。(已修改为AC代码)

#include 
int main()
{
    int h, r,n = 0;
    double v,pi=3.14;
    scanf("%d%d", &h, &r);
    v = pi* r * r * h;
        n = 20000 / v + 1;
    printf("%d", n);
    return 0;
}

13、P1425 小鱼的游泳时间

#include 
#include 
int main()
{int a,b,c,d,e,f;
int m,n;
scanf("%d %d %d %d",&a,&b,&c,&d);
m=a*60+b;
n=c*60+d;
e=(n-m)/60;
f=(n-m)%60;
    printf("%d %d",e,f);
    return 0;
}

14、P1421 小玉买文具

#include 
#include 

int main()
{int a,b,c=19,d;
scanf("%d %d",&a,&b);
a=a*10;
d=(a+b)/c;
printf("%d",d);
    return 0;
}

15、P3954 [NOIP2017 普及组] 成绩

#include 
#include 
#include 
#include 
int main()
{
    int a,b,c,sum;
    scanf("%d %d %d",&a,&b,&c);
    sum=a*0.2+b*0.3+c*0.5;
    printf("%d",sum);
    return 0;


}

你可能感兴趣的:(C语言,c语言,算法,开发语言,vscode,单片机)