牛客網第十二天的訓練
阿新 • • 發佈:2018-11-24
基礎題: 字母統計
#include<iostream> #include<algorithm> #include<map> using namespace std; bool isjudge(char c); int main() { string s; while(cin>>s) { map<char,int> m; for(int i=0;i<26;++i) { m[i+'A']=0; } for(int i=0;i<s.length();++i) { if(isjudge(s[i])) continue; m[s[i]]++; } map<char,int> :: iterator it; for(it=m.begin();it!=m.end();it++) { cout<<it->first<<":"<<it->second<<endl; } } return 0; } bool isjudge(char c) { if(c<'A' || c>'Z') return true; return false; }
進階題:牛牛的鬧鐘
#include<iostream> #include<algorithm> #define INF 0x3f3f3f3f using namespace std; const int maxn = 1e4+5; struct node{ int h,s; int t; }a[maxn]; int main() { int n,time; node aim; while(cin>>n) { for(int i=0;i<n;++i) { cin>>a[i].h>>a[i].s; a[i].t=a[i].h*60+a[i].s; } cin>>time; //需要花費的時間 cin>>aim.h>>aim.s; aim.t=aim.h*60+aim.s; int dis=INF,sp,ans_h,ans_s; for(int i=0;i<n;i++) { sp=aim.t-a[i].t; //當前鬧鐘與上課時間差 if(sp<time) continue; if(sp<dis) { ans_h=a[i].h,ans_s=a[i].s; dis=sp; } } cout<<ans_h<<" "<<ans_s<<endl; } return 0; }