生活随笔
收集整理的這篇文章主要介紹了
Acwing第 33 场周赛【完结】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 4206. 判斷數字【水題】
- 4207. 最長合法括號子序列【思維】
- 4208. 電話號碼【模擬】
4206. 判斷數字【水題】
#include<bits/stdc++.h>
using namespace std
;
int main(void)
{int cnt1
=0,cnt2
=0;string s
; cin
>>s
;for(int i
=0;i
<s
.size();i
++){if(s
[i
]=='4') cnt1
++;if(s
[i
]=='7') cnt2
++;}cnt1
+=cnt2
;if(cnt1
==4||cnt1
==7) puts("YES");else puts("NO");return 0;
}
4207. 最長合法括號子序列【思維】
https://www.acwing.com/problem/content/4210/
只要時刻保持,左括號的數量大于右括號的數量即可。
#include<bits/stdc++.h>
using namespace std
;
int cnt1
,cnt2
,ans
;
int main(void)
{string s
; cin
>>s
;for(int i
=0;i
<s
.size();i
++){if(s
[i
]=='(') cnt1
++;if(s
[i
]==')') cnt2
++;if(cnt1
>=cnt2
) ans
=max(ans
,cnt2
*2);else cnt2
--;}cout
<<ans
;return 0;
}
4208. 電話號碼【模擬】
https://www.acwing.com/problem/content/description/4211/
數據范圍很小,直接按照題意模擬即可。
#include<bits/stdc++.h>
#define YES puts("YES");
#define Yes puts("Yes");
#define yes puts("yes");
#define NO puts("NO");
#define No puts("No");
#define no puts("no");
using namespace std
;
typedef long long int LL
;
typedef pair
<int,int> PII
;
const int N
=1e5*2+10;
const int mod
=1e9+7;
int n
,m
;
map
<string
,vector
<string
>>mp
;
vector
<string
>ans
[N
];
vector
<string
>s
,temp
;
int main(void)
{cin
>>n
;for(int i
=0;i
<n
;i
++){string name
; cin
>>name
;scanf("%d",&m
);for(int j
=0;j
<m
;j
++){string id
; cin
>>id
;mp
[name
].push_back(id
);}}int k
=0;for(auto i
=mp
.begin();i
!=mp
.end();i
++){s
.push_back(i
->first
);map
<string
,int>hush
;temp
=i
->second
;for(int j
=0;j
<temp
.size();j
++) hush
[temp
[j
]]++;for(auto j
=hush
.begin();j
!=hush
.end();j
++){auto ss
=j
->first
;string sss
;for(int z
=ss
.size()-1;z
>=1;z
--){sss
=ss
[z
]+sss
;hush
[sss
]=-1;}}for(auto j
=hush
.begin();j
!=hush
.end();j
++){if(j
->second
!=-1) ans
[k
].push_back(j
->first
);}k
++;}cout
<<s
.size()<<endl
;for(int i
=0;i
<s
.size();i
++){cout
<<s
[i
]<<" "<<ans
[i
].size();for(int j
=0;j
<ans
[i
].size();j
++) cout
<<" "<<ans
[i
][j
];cout
<<endl
;}return 0;
}
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的Acwing第 33 场周赛【完结】的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。