一、字符串
#include<bits/stdc++.h>
using namespace std;
int main()
{
map<int,int>hash;
string s;
while(cin>>s)
{
if(s=="*#*")
break;
for(char x : s)
{
if(isdigit(x))
{
int digit=x-'0';
hash[digit]++;
}
}
}
for(int i=0;i<10;i++)
{
printf("%d出现的次数为%d\n",i,hash[i]);
}
return 0;
}
二、成绩排名
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
struct Student
{
string name;
int score;
bool operator > (const Student& t)const
{
return score>t.score;
}
}student[N];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
string name;
int score;
cin>>name>>score;
student[i]={name,score};
}
stable_sort(student,student+n,greater<Student>());
for(int i=0;i<n;i++)
cout<<student[i].name<<" "<<student[i].score<<endl;
return 0;
}
三、计算日期
#include<bits/stdc++.h>
using namespace std;
const int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int is_leapyear(int y)
{
if(y%400==0||(y%4==0&&y%100!=0))
return 1;
else
return 0;
}
int get_day(int y,int m)
{
return is_leapyear(y)+month[m];
}
int main()
{
int y,m,d;
cin>>y>>m>>d;
int days=0;
while(d--)
{
days++;
if(!d)
{
m--;
d=get_day(y,m);
if(!m)break;
}
}
cout<<days<<endl;
return 0;
}
四、分组问题 8会