A.
直接输出
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
cout<<"Good code is its own best documentation."<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
//cin>>hey_left;
while(hey_left--){
solve();
}
}
B.
直接输出
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
int x;cin>>x;
cout<<"print("<<x<<")"<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
//cin>>hey_left;
while(hey_left--){
solve();
}
}
C.
if else 输出
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
int n;cin>>n;
string x;cin>>x;
//cout<<x<<'\n';
int m,k;cin>>m>>k;
if(k==n)cout<<"mei you mai "<<x<<" de"<<'\n';
else if(k==m)cout<<"kan dao le mai "<<x<<" de"<<'\n';
else cout<<"wang le zhao mai "<<x<<" de"<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
//cin>>hey_left;
while(hey_left--){
solve();
}
}
D.
二分猜数字
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
int n;cin>>n;
int l=1,r=n,mid;
int ans;
while(l<=r){
mid=(l+r)/2;
cout<<mid<<endl;
string s;cin>>s;
if(s.size()==1)r=mid-1;
else {
ans=mid;
l=mid+1;
}
}
cout<<"! "<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
//cin>>hey_left;
while(hey_left--){
solve();
}
}
E.
两个字符串分别处理完再比较是否相同
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
string s1,s2;cin>>s1>>s2;
string t1="",t2="";
for(int i=1;i<s1.size();i++){
if(s1[i]%2==s1[i-1]%2){
t1+=max(s1[i],s1[i-1]);
}
}
for(int i=1;i<s2.size();i++){
if(s2[i]%2==s2[i-1]%2){
t2+=max(s2[i],s2[i-1]);
}
}
if(t1==t2)cout<<t1<<'\n';
else {
cout<<t1<<'\n'<<t2<<'\n';
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
//cin>>hey_left;
while(hey_left--){
solve();
}
}
F.
字符串各种函数的运用
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
string s;cin>>s;
int n;cin>>n;
while(n--){
int l,r;cin>>l>>r;
string st,en;cin>>st>>en;
string t=s.substr(l-1,r-l+1);
s=s.substr(0,l-1)+s.substr(r,s.size()-r);
en=st+en;
int id=s.find(en);
if(id==-1||id>0x3f3f3f3f)s+=t;
else{
s.insert(id+st.size(),t);
}
}
cout<<s<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
//cin>>hey_left;
while(hey_left--){
solve();
}
}
G.
排序+计数
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
void solve(){
int n;cin>>n;
vector<int>a,cnt(N);
for(int i=1,x;i<=n;i++){
cin>>x;
if(cnt[x])cnt[x]++;
else {
a.push_back(x);
cnt[x]++;
}
}
sort(a.begin(),a.end());
cout<<a[0]<<' '<<cnt[a[0]]<<'\n';
cout<<a[a.size()-1]<<' '<<cnt[a[a.size()-1]];
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
//cin>>hey_left;
while(hey_left--){
solve();
}
}
H.
枚举,判素数
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
void solve(){
int l,k;cin>>l>>k;
string s;cin>>s;
if(k>s.size()){
cout<<"404"<<'\n';
return ;
}
for(int i=0;i<=s.size()-k;i++){
int sum=0;
for(int j=i;j<i+k;j++){
sum=sum*10+(s[j]-'0');
}
if(sum==0||sum==1)continue;
bool f=0;
for(int j=2;j*j<=sum;j++){
if(sum%j==0){
f=1;
break;
}
}
if(f)continue;
printf("%0*lld\n",k,sum);
return ;
}
cout<<"404";
}
signed main(){
//ios::sync_with_stdio(false);
//cin.tie(0);cout.tie(0);
int hey_left=1;
//cin>>hey_left;
while(hey_left--){
solve();
}
}
J.
模拟,用栈、队列、vector
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
vector<vector<int>>ans;
int n,m,k;cin>>n>>m>>k;
stack<int>box;
vector<int>tree;
queue<int>push;
for(int i=1,x;i<=n;i++){
cin>>x;
push.push(x);
}
while(box.size()||push.size()){
int tmp;
if(tree.size()!=0)tmp=tree.back();
else tmp=0x3f3f3f3f;
if(box.size()!=0&&box.top()<=tmp){
tree.push_back(box.top());
box.pop();
if(tree.size()==k){
ans.push_back(tree);
tree.clear();
}
}else if(push.size()!=0&push.front()<=tmp){
tree.push_back(push.front());
push.pop();
if(tree.size()==k){
ans.push_back(tree);
tree.clear();
}
}else if(push.size()&&box.size()<m){
box.push(push.front());;
push.pop();
}else{
ans.push_back(tree);
tree.clear();
}
}
if(tree.size()!=0){
ans.push_back(tree);
}
for(int i=0;i<ans.size();i++){
for(int j=0;j<ans[i].size();j++){
cout<<ans[i][j];
if(j!=ans[i].size()-1)cout<<' ';
}
cout<<'\n';
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
//cin>>hey_left;
while(hey_left--){
solve();
}
}
标签:winter,int,SMU,hey,long,cin,2024,solve,left
From: https://www.cnblogs.com/wwww-/p/17990795