zoukankan      html  css  js  c++  java
  • 第一章:程序设计入门

    2018-10-18-13:08:45

    随学笔记:

    小计:

     <1>: ACM比赛中不能使用#include<conio.h> 中包含的getch(),clrscr()等函数,不能使用getche(),gotoxy()等函数。

     <2>: 算法竞赛中如发现题目有异议应向相关人员询问,不应主观臆断。

      例如: 例题1-2中所讲三位数翻转末尾0是否输出。

     <3>: 尽量使用const关键字申明常数。

      例如:const double Pi =acos(-1.0);

     <4>: 逻辑运算符:

      &&和&

                & 无论左边结果是什么,右边还是继续运算;

                &&当左边为假,右边不再进行运算。

                但是两者的结果是一样的

      ||和|   

        | 无论左边结果是什么,右边还是继续运算;

                  ||当左边为真,右边不再进行运算。

                  但是两者的结果是一样的

      无特殊要求情况下,相比之下&&和||更高效。

     <5>: 平时练习和写模板时应适当添加注释让别人更容易理解,让自己保持思路清晰。

      //内容    OR

      /*   内容   */

    例题1-1:

      <1>:浮点型输入输出时:float输入输出都是%f,double输入时为%lf,输出时为%f。

      

     1 #include <cstdio>
     2 #include <iostream>
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     double t1;
     8     scanf("%lf",&t1);
     9     printf("%f\n",t1);
    10 
    11     float t2;
    12     scanf("%f",&t2);
    13     printf("%f\n",t2);
    14     
    15     return 0;
    16 }

      <2>:圆周率π用表达式 acos(-1.0)表示。

         这其中acos为math.h里的函数,double acos(double x);//x∈[-1,1]。//应用函数时记得申明头文件#include<cmath>

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <iostream>
     4 using namespace std;
     5 const double Pi =acos(-1.0);
     6 int main()
     7 {
     8 
     9     printf("%f\n",Pi);
    10 
    11     return 0;
    12 }

       相关习题及代码:

    1-4: 正弦和余弦

     输入integer n,输入n的正弦和余弦值。

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <iostream>
     4 using namespace std;
     5 const double Pi=acos(-1.0);
     6 
     7 int main()
     8 {
     9     int n;
    10     while(~scanf("%d",&n)){
    11         double x=n*1.0/180*Pi;
    12         printf("%.2f\n%.2f\n",sin(x),cos(x));
    13     }
    14     return 0;
    15 }

    课后问题:

       <1>: int 型数值的最大表示范围:

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <iostream>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int n1=1,cnt1=1;
     9     while(++n1>0)
    10       cnt1++;
    11     printf("%d\n",cnt1);
    12 
    13     int n2=-1,cnt2=-1;
    14     while(--n2<0)
    15       cnt2--;
    16     printf("%d\n",cnt2);
    17     return 0;
    18 }

      <2>: else总是与他前面离他最近的未配对的if配对。

     1 #include <cstdio>
     2 #include <iostream>
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     int a=1,b=2;
     8     if(a)
     9       if(b)
    10         a++;
    11       else
    12         b++;
    13     printf("%d\n%d\n",a,b);
    14 
    15      return 0;
    16 }


      /*可替换代码为
        if(a)
      b ? a++:b++;
      */
    时间并不会因为你的迷茫和迟疑而停留,就在你看这篇文章的同时,不知道有多少人在冥思苦想,在为算法废寝忘食,不知道有多少人在狂热地拍着代码,不知道又有多少提交一遍又一遍地刷新着OJ的status页面…… 没有谁生来就是神牛,而千里之行,始于足下!
  • 相关阅读:
    卸载全部appx应用(包括应用商店)
    重置 Launchpad 和更新APP图标缓存
    删除OSX中第三方的「偏好设置」程序(.prefPane)
    IOS segue(跳转页面处理)
    IOS NSNotificationCenter(通知 的使用)监听文本框的文字改变
    IOS UITextFieldDelegate (常用的代理方法)
    IOS UIActionSheet(底部 弹出框的使用)
    IOS 偏好设置数据 存 取(Preferences文件夹)
    IOS plist的数据 存 取(沙河目录)
    显示 Mac隐藏的文件夹 命令语句
  • 原文地址:https://www.cnblogs.com/bianjunting/p/9809895.html
Copyright © 2011-2022 走看看