PAT 知识点整理

Pat最终题目整理

一:几个函数

①Reverse()函数; stoi将字符串类型转为int型 ;to_string关键字

头文件:#include;

#include

usingnamespace std;

intmain()

{

      int a,b;

      cin>>a>>b;

    string c;

stringresult=to_string(a*b);

reverse(result.begin(),result.end());

}



②Abs函数() 输出绝对值

头文件#include

例:C=(double)abs(A-B);



③Set的insert()函数

C++ 有这样一个容器,即 STL 中的 set (可以百度一下是什么东西),set 的特性是其内所包含的元素的值唯一,利用这一特性,只要输出最终set 中元素的个数即可

#include

usingnamespace std;

intmain(){

      set s;

      int n;

      cin>>n;

      for(int i=1;i<=n;i++)

              s.insert(i/2+i/3+i/5);

      cout<

      return 0;

}



④strlen计算长度函数

sizeof可以用类型做参数,strlen只能用char*做参数,且必须是以'\0'结尾的。

scanf("%s", str);

  int len = strlen(str);

⑤德才论中的sort函数

头文件:#include

排序条件不够可以在sort函数末尾加上排序条件;

利用comp函数修改条件 但记住最后一定加上else return false;

判断条件:第一个true不满足条件向下继续判断;

bool comp(Stu x, Stu y) {

    if (x.s1 + x.s2 > y.s1 + y.s2) return true;

    else if (x.s1 + x.s2 == y.s1 + y.s2 && x.s1 > y.s1) return true;

    else if (x.s1 + x.s2 == y.s1 + y.s2 && x.s1 == y.s1 && x.num < y.num) return true;

    else return false;

}

********省略

sort(stu1.begin(), stu1.end(), comp);

程序猿


先写这些吧;

你可能感兴趣的:(PAT 知识点整理)