AcWing 3199. 命令行选项
原题链接
中等
作者:
Carson_
,
2024-12-06 15:20:11
,
所有人可见
,
阅读 2
stringstream来分割字符串
C++ 代码
#include<bits/stdc++.h>
#define x first
#define y second
#define LL long long
#define PII pair<int, int>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f
#define rep(i,a,n) for(int i = a; i <= n; ++i)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) x.begin(), x.end()
#define lowbit(x) (x&-x)
#define int long long
using namespace std;
const int N=1e6+10,mod=1e9+7,MOD=998244353;
int qmi(int a,int b)
{
int res=1;
a%=mod;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res%mod;
}
int fac[N],ifac[N];
void init()
{
int n=1e6+1;
fac[0]=ifac[0]=1;
rep(i,1,n)
{
fac[i]=fac[i-1]*i%mod;
ifac[i]=ifac[i-1]*qmi(i,mod-2)%mod;
}
}
int C(int n,int m)
{
if(n>=m&&m>=0)
{
return fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
else return 0;
}
void solve()
{
string s;
cin>>s;
map<char,int> mp;
for(int i=0;i<s.size();i++)
{
if(s[i]>='a'&&s[i]<='z')
{
if(s[i+1]==':') mp[s[i]]=2;
else mp[s[i]]=1;
}
}
int n;
cin>>n;
getchar(); //*******/
rep(i,1,n)
{
string ss;
getline(cin,ss);
stringstream ssin(ss);//** 字符流 去掉中间空格 分割处理 **/
vector<string> v;
while(ssin>>ss) v.push_back(ss);
map<char,string>ans;
//if(i==1) cout<<v.size()<<endl;
// for(auto i:v) cout<<i<<endl;
for(int j=1;j<v.size();j++)
{
string t=v[j];
if(t[0]!='-'||t[1]<'a'||!mp.count(t[1])||t.size()>2) break;
else
{
if(mp[t[1]]==1)
{
ans[t[1]]=t[1];
}
else if(mp[t[1]]==2)
{
if(j+1<v.size())
{
ans[t[1]]=v[j+1];
j++;
}
}
}
}
cout<<"Case "<<i<<':'<<' ';
for(auto c:ans)
{
if(mp[c.x]==1) cout<<'-'<<c.x<<' ';
else if(mp[c.x]==2)
{
cout<<'-'<<c.x<<' '<<c.y<<' ';
}
}
cout<<endl;
}
}
signed main()
{
//IOS;
int t=1;
//cin>>t;
while(t--) solve();
}
// (( )) ()()
//10 6 2 0 9 3 4
//2 3 9 4
//
// 3 4 4 4 5 5 6
//12 3456 7