1. 字符串
#include
using namespace std;
string str;
int main(){
cin>>str;
for(string::iterator i=str.begin();i!=str.end();){
if(*i>='0'&&*i<='9'){
i=str.erase(i);
}else{
++i;
}
}
cout<<str;
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
2. 统计
#include
using namespace std;
int n,m;
int f(int n,int m){
int cnt=0;
if(!(0<=n&&n<=9)){
return -1;
}
while(m){
if(m%10==n){
++cnt;
}
m/=10;
}
return cnt;
}
int main(){
cin>>n>>m;
cout<<f(n,m);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
3. 学生上课率旷课率统计
#include
using namespace std;
int stuNum,clazzNum;
map<string,vector<string> > students;
void countOne(string no){
vector<string> status=students[no];
double cnt1=0,cnt2=0;
for(int i=0;i<clazzNum;++i){
if(status[i]=="正常"||status[i]=="迟到"){
++cnt1;
}else if(status[i]=="旷课"){
++cnt2;
}
}
cout<<no<<"\t上课率: "<<cnt1/clazzNum*100<<"%\t旷课率: "<<cnt2/clazzNum*100<<"%"<<endl;
}
void countAll(){
for(map<string,vector<string> >::iterator i=students.begin();i!=students.end();++i){
countOne(i->first);
}
}
int main(){
cin>>stuNum>>clazzNum;
for(int i=0;i<stuNum;++i){
string no;
vector<string> status;
cin>>no;
for(int j=0;j<clazzNum;++j){
string temp;
cin>>temp;
status.push_back(temp);
}
students[no]=status;
}
countAll();
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46