模拟就可以了
先把所有的空格去掉,然后把大小写统一,然后依次进行处理
首先分离出函数名,然后把左括号分离出,然后依次读取每一个参数,以逗号隔开的
如果参数中有字符
‘a’的’
说明这是个char类型,然后在函数参数中写上char
没有这个符号就是int类型,写上int
处理到最后把右括号加上去
放到set中
输出集合的大小即可
diss:洛谷oj,\r\n?
因为读取了一个数字,接下来要读取一行字符,因此需要用getchar ()把换行符读取掉,不会真的有\r\n吧
一次getchar()或者cin.get()读取不掉
需要读取两次
有几个样例明明在本机跑的时候就没有任何问题,和标准输出一样,但是放到洛谷的IDE就出问题,我又放到牛客的IDE跑了一遍,和本机一样,谁的问题不说了吧
理论标程
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
//#define LOCAL_MACHINE
const int INF = 1 << 30;
const int mod = 998244353;
const int N = INF;
int n;
string solve(string s);
set<string> st;
void in(){
cin >> n;
cin.get();//除了此处不一样,其余都一样
rep (i, 1, n){
string s;
getline(cin, s);
string t = solve(s);
if (t == "main")continue;
st.insert(t);
}
cout << st.size() << "\n";
}
string solve(string s){
string t = "";
int len = s.length();
rep (i, 0, len - 1){
if (s[i] == ' ')continue;
if (s[i] >= 'A' && s[i] <= 'Z')s[i] += 32;
t += s[i];
}
int be = 0;
string ans = "";
while (be < len && t[be] != '('){
ans += t[be];
be++;
}
if (ans == "main")return ans;
ans += "(";
be++;
bool fir = 1;
while (be < len){
string t = "";
while (be < len && s[be] != ',' && s[be] != ')'){
t += s[be];
be++;
}
be++;
if (!fir)ans += ",";
fir = 0;
int lent = t.length();
bool f = 1;
rep (i, 0, lent - 1){
if (t[i] == '\''){
f = 0;
}
}
if (f) ans += "int";
else ans += "char";
}
ans += ")";
return ans;
}
int main(){
#ifdef LOCAL_MACHINE
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
in();
// solve();
return 0;
}
实际标程
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define LOCAL_MACHINE
const int INF = 1 << 30;
const int mod = 998244353;
const int N = INF;
int n;
string solve(string s);
set<string> st;
void in(){
cin >> n;
cin.get();cin.get();//除了此处不一样,其余都一样
rep (i, 1, n){
string s;
getline(cin, s);
string t = solve(s);
if (t == "main")continue;
st.insert(t);
}
cout << st.size() << "\n";
}
string solve(string s){
string t = "";
int len = s.length();
rep (i, 0, len - 1){
if (s[i] == ' ')continue;
if (s[i] >= 'A' && s[i] <= 'Z')s[i] += 32;
t += s[i];
}
int be = 0;
string ans = "";
while (be < len && t[be] != '('){
ans += t[be];
be++;
}
if (ans == "main")return ans;
ans += "(";
be++;
bool fir = 1;
while (be < len){
string t = "";
while (be < len && s[be] != ',' && s[be] != ')'){
t += s[be];
be++;
}
be++;
if (!fir)ans += ",";
fir = 0;
int lent = t.length();
bool f = 1;
rep (i, 0, lent - 1){
if (t[i] == '\''){
f = 0;
}
}
if (f) ans += "int";
else ans += "char";
}
ans += ")";
return ans;
}
int main(){
#ifdef LOCAL_MACHINE
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
in();
// solve();
return 0;
}