目录
题目一:
代码:
题目二:
代码:
题目三:
代码:
题目四:
代码:
题目五:
代码:
题目六:
代码:
题目七:
代码:
题目八:
代码:
题目九:
代码:
题目十:
代码:
题目一:
代码:
#include<iostream>
using namespace std;
int main()
{string s;cin>>s;if(s.size()==4){if(s[0]<'2'||(s[0]=='2'&&s[1]<'2'))cout<<"20"<<s[0]<<s[1]<<"-"<<s[2]<<s[3]<<endl;elsecout<<"19"<<s[0]<<s[1]<<"-"<<s[2]<<s[3]<<endl;}elsecout<<s[0]<<s[1]<<s[2]<<s[3]<<"-"<<s[4]<<s[5]<<endl;
}
题目二:
代码:
#include<iostream>
using namespace std;
int main()
{int a[25];for(int i=0;i<=23;i++)cin>>a[i];int x;cin>>x;while(x>=0&&x<=23){cout<<a[x]<<" ";if(a[x]>50)cout<<"Yes"<<endl;elsecout<<"No"<<endl;cin>>x;}
}
题目三:
代码:
#include <iostream>
#include <string>
using namespace std;
int main()
{int n,m;cin >> n >> m;getchar();string s[100];int a[100];int k = 0;for(int i = 0; i < n; i ++){getline(cin,s[i]);if(s[i].find("qiandao") == -1 && s[i].find("easy") == -1) //没找到这两个a[k++] = i;//存下标}if(k <= m)//m大于等于k,表示做完了cout << "Wo AK le" << endl;elsecout << s[a[m]] << endl;
}
题目四:
代码:
#include<iostream>
#include<map>
using namespace std;
map<int, int>mp;
int main()
{int n, maxx = 0, minn = 1e7;cin >> n;for (int i = 1; i <= n; i++){int x;cin >> x;mp[x]++;//记录出现次数if (x > maxx)//求最大值maxx = x;if (x < minn)//求最小值minn = x;}for (auto i : mp){if (i.first == minn)cout << minn << " " << mp[minn] << endl;if (i.first == maxx)cout << maxx << " " << mp[maxx];}
}
题目五:
代码:
#include<iostream>
using namespace std;
int main()
{int a1, a2, n;cin >> a1 >> a2 >> n;int a[1010];a[1] = a1, a[2] = a2;int k = 3;//第三个开始,代表存到第几个int cnt=3;//从第三个开始,代表乘的编号while (1){int x = a[cnt - 1] * a[cnt - 2];cnt++;int s=-1,g=-1;if(x<10){a[k++]=x%10;}else{g=x%10;x/=10;s=x%10;a[k++]=s;a[k++]=g;}if (k >= n + 1)break;}for (int i = 1; i <= n; i++){if (i != 1)cout << " ";cout << a[i];}}
题目六:
代码:
#include<iostream>
#include<queue>
#include<stack>
using namespace std;
int main()
{stack<char> st;int n,m,s;cin>>n>>m>>s;queue<char> a[10005];for(int i=1;i<=n;i++){char e;for(int j=1;j<=m;j++){cin>>e;a[i].push(e);//存入编号为i的轨道}}int t;while(cin>>t&&t!=-1){if(t==0&&st.size()!=0)//篮子里有,拿篮子里的{cout<<st.top();st.pop();}else if(t!=0)//不拿篮子里的{if(a[t].size()==0)//该轨道空了continue;else{if(st.size()==s)//篮子满了,拿出一个{cout<<st.top();st.pop();}st.push(a[t].front());//再把轨道上的放到篮子里a[t].pop();}}}
}
题目七:
代码:
#include<iostream>
#include<vector>
using namespace std;
vector<int> e[10100];
int book[10100] = { 0 };
vector<int> step;
vector<int> len;
int maxx = 0;
void dfs(int k)
{if (e[k].size() == 0)//判断是否到头{int l = step.size();if (l > maxx)//更长,则更新{maxx = l;len = step;}if (l == maxx && step < len)///相等,但是序号更小,更新len = step;return;}for (auto i : e[k]){step.push_back(i);dfs(i);step.pop_back();}return;
}
int main()
{int n;cin >> n;for (int i = 0; i < n; i++){int k;cin >> k;while (k--){int x;cin >> x;e[i].push_back(x);//建边book[x] = 1;//标记出现}}for (int i = 0; i < n; i++){if (book[i] == 0)//没出现的为根,从根开始深度遍历{step.push_back(i);dfs(i);break;}}cout << len.size() << endl;for (int i=0;i<len.size();i++){if(i!=0)cout<<" ";cout<<len[i];}
}
题目八:
代码:
#include<iostream>//最后一个点超时,可以考虑把vector改成string
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
map<vector<int>, int>mp;
struct node
{vector<int> tmp;int cnt;
};
bool cmp(node a,node b)
{if(a.cnt==b.cnt)//次数相等return a.tmp<b.tmp;//按vector小的在前return a.cnt>b.cnt;//次数大的在前
}
int main()
{int n, m;cin >> n >> m;for (int i = 0; i < n; i++){vector<int> v;for (int j = 0; j < m; j++){int x;cin >> x;v.push_back(x);}if (mp.count(v) < 1)//没有则建立mp[v] = 1;else//有则加加mp[v]++;}multimap<int, vector<int>> v;//一个一对多的存储容器for (auto i : mp){v.insert({ i.second,i.first });//键和值反过来存}cout<<v.size()<<endl;node ans[101000];int t=0;for (auto i : v){ans[t].cnt=i.first,ans[t++].tmp=i.second;//存次数和值}sort(ans,ans+t,cmp);//排序for(int i=0;i<t;i++){cout<<ans[i].cnt;for(auto j:ans[i].tmp)//访问该vector{cout<<" "<<j;}cout<<endl;}
}
题目九:
代码:
#include<iostream>
#include<vector>
using namespace std;
vector<int> e[101010];
int main()
{int n, m;cin >> n >> m;for (int i = 1; i <= n; i++){int k;cin >> k;while (k--){int x;cin >> x;e[i].push_back(x);//存边}}int pos = 1;//记录剧情点int c[110];while (m--){int a, b;cin >> a >> b;if (a == 1)//存档{c[b] = pos;cout << pos << endl;}else if (a == 0)//切档{pos = e[pos][b-1];}else if (a == 2)//读档{pos = c[b];}}cout << pos << endl;//最后位置
}
题目十:
代码:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct node
{string s;int id,t;
};
node s[101000];
bool cmp(node a,node b)
{return a.id>b.id;
}
bool cmp1(node a,node b)
{return a.t<b.t;
}
int main()
{int n;cin >> n;string str;getchar();getline(cin, str);int m;cin >> m;for (int i = 0; i < m; i++){int k;cin >> k;getchar();getline(cin, s[i].s);s[i].id=i+1;}sort(s,s+m,cmp);for(int i=0;i<m;i++){int d=str.find(s[i].s);s[i].t=d;int cnt=0;for(int j=d;;j++){if(str[j]==' '){str[j]='*',cnt++;//cout<<str<<endl;}if(cnt==2)break;}}sort(s,s+m,cmp1);for(int i=0;i<m;i++){if(i!=0)cout<<" ";cout<<s[i].id;}
}