c/c++语言开发共享10.22 学习总结

1. double ceil(double x) 求大于 x 的最小的数,即向上取整函数 2.A 65 Z 90 a 97 z 122 3.字符串删除 https://blog.csdn.net/yishizuofei/article/details/79059804 C++ string 字符串删 …

1. double ceil(double x)

求大于 x 的最小的数,即向上取整函数

#include<bits/stdc++.h>  using namespace std;  int main(){      long long n,m,a;      cin>>n>>m>>a;      long long s=ceil(m*1.0/a)*ceil(n*1.0/a);      //或写为      //long long s=((m+a-1)/a)*((n+a-1)/a);      cout<<s<<endl;      return 0;   }

2.a   65    z    90

   a   97    z     122

 

3.字符串删除 

  

  c++ string 字符串删除指定字符  

  c++从string中删除所有的某个特定字符     超好

#include<bits/stdc++.h>  using namespace std;  int main(){      string str;      cin>>str;      str.erase(remove(str.begin(),str.end(),'a'),str.end());      cout<<str<<endl;      return 0;  }

 

5. 字符串 大写 改为 小写

for(int i=0;i<str.size();i++){          str[i]=tolower(str[i]);      }

 小写改为大写

toupper();

 

 

6.字符串  str1 中是否有字符字串  str2

strstr()函数    

  extern char *strstr(char *str1, char *str2);

  作用:返回str2 在str1中第一次出现的位置(地址)

c_str() 函数

  作用:c_str()函数返回一个指向正规c字符串的指针, 内容与本string串相同.,

            这是为了与c语言兼容,在c语言中没有string类型,故必须通过string类对象的成员函数c_str()把string 对象转换成c中的字符串样式。

string str;      string str2="1111111";      if(strstr(str.c_str(),str2.c_str())!=null)flag=true;      else flag=false;

 

what do we need caps lock for?

caps lock is a computer keyboard key. pressing it sets an input mode in which typed letters are capital by default. if it is pressed by accident, it leads to accidents like the one we had in the first passage.

let’s consider that a word has been typed with the caps lock key accidentally switched on, if:

  • either it only contains uppercase letters;
  • or all letters except for the first one are uppercase.

in this case we should automatically change the case of all letters. for example, the case of the letters that form words “hello“, “http“, “z” should be changed.

write a program that applies the rule mentioned above. if the rule cannot be applied, the program should leave the word unchanged.

input

the first line of the input data contains a word consisting of uppercase and lowercase latin letters. the word’s length is from 1 to 100 characters, inclusive.

output

print the result of the given word’s processing.

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/601274.html

(0)
上一篇 2021年5月9日
下一篇 2021年5月9日

精彩推荐