PTA 乙级题整理

*1. set<int >a  存进数据去可以去掉重复的

*2. %02d  表示输出的数字占两个位置,不够的用0 补齐

3. abs( )求绝对值,不用其他的头文件

4. 去重函数

void remove(char str[]) {
    int len = strlen(str);
    int ascii[128] = {0};
    int p = 0;
    int i;
    for (i=0; i<len; i++) {
        if (ascii[str[i]] == 0) {
            ascii[str[i]] = 1;
            str[p++] = str[i];
        }
    }
    str[p] = '\0';
}

5. #include <cctype>      toupper()小写字母转换成大写字母

6. 要注意使用数组下标巧妙的解决问题

  7. 进制转换

while(sum/c){
   	temp[i]=sum%c;
   	i++;
   	sum=sum/c;
   }
   temp[i]=sum;
   for(int j=i;j>=0;j--){
   	cout<<temp[j];
   }

8. 注意找规律

*9.sort排序

 bool MySort(int a,int b) {

       return a>b;//从大到小

}

sort(&p[0],&p[n],MySort);//sort(p,p+n,Mysort)

10. return用于结束一个函数的执行,将函数的执行信息传出给其他调用函数使用;exit函数是退出应用程序,删除进程使用的内存空间,并将应用程序的一个状态返回给OS或其父进程,这个状态标识了应用程序的一些运行信息,这个信息和机器和操作系统有关,一般是 0 为正常退出, 0 为非正常退出。

11. int gcd(int a, int b) {

   return b == 0 ? a : (b, a%b);

}//最小公倍数

int lcm(int a, int b) {

   return a*b/gcd(a, b);

}//最大公倍数

12. map 映射, STL 中提供的模板类
map<string, int> mymap; 提供一种对应关系,就是一个string对应一个int 这种关系
比如:
"星期天" 对应 7
"星期一"对于 1
这种形式

 

猜你喜欢

转载自blog.csdn.net/red_red_red/article/details/87560976
今日推荐