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.字串洗掉
https://blog.csdn.net/yishizuofei/article/details/79059804
C++ string 字串洗掉指定字符https://blog.csdn.net/lynn_xl/article/details/89151535
C++從string中洗掉所有的某個特定字符 https://www.cnblogs.com/7z7chn/p/6341453.html 超好
#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; }
洗掉特定字串簡單做法
int pos=0;//下標 while( (pos=str.find("WUB"))!=-1 ){ str.erase(pos,3); }
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;
7.字串插入字符
https://blog.csdn.net/wang1997hi/article/details/78364755
http://codeforces.com/problemset/problem/208/A
cf 208 A 考察了洗掉和插入
str.insert(pos,str2);
cf 208 A
#include<bits/stdc++.h> using namespace std; int main(){ string str; cin>>str; int pos=0;//下標 while( (pos=str.find("WUB"))!=-1 ){ str.erase(pos,3); if(str[pos-1]!=' '&&pos!=0)str.insert(pos," "); } cout<<str<<endl; return 0; } str.insert(pos,str2);View Code
8.字串輸入空格
cin.getline(str,15);
cin.getline(接受字串到m,接受個數5,結束字符)
getline(cin,str) // 接受一個字串,可以接收空格并輸出,需包含“#include<string>”
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/93384.html
標籤:C++
上一篇:c++11多執行緒記錄0
下一篇:實驗作業
