2023年9月14日
题目不难,但是有点恶心。今天写的这个是真受制
ACWING1478 签到签出
题目理解
这个就是要把时间都转化成秒,然后排序即可。
代码实现
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
pair<int, int> in[12], out[12];
string a[12];
int to_second(string k)
{
int h = 0, min = 0, s = 0;
h += (int)k[0] - 48;
h *= 10;
h += (int)k[1] - 48;
h *= 3600;
min += (int)k[3] - 48;
min *= 10;
min += (int)k[4] - 48;
min *= 60;
s += (int)k[6] - 48;
s *= 10;
s += (int)k[7] - 48;
return h + min + s;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
string time1, time2;
cin >> time1 >> time2;
in[i].first = to_second(time1);
out[i].first = to_second(time2);
in[i].second = i;
out[i].second = i;
}
sort(in + 1, in + 1 + n);
sort(out + 1, out + 1 + n);
cout << a[in[1].second] << " " << a[out[n].second];
return 0;
}
ACWING1519 密码
题目理解
模拟即可。
代码实现
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
const int N = 1010;
bool st[N];
bool check(string p)
{
for(int i = 0; i < p.size(); i++)
if(p[i] == '0' || p[i] == '1' || p[i] == 'l' || p[i] == 'O')
return true;
return false;
}
string change(string p)
{
string res = "";
for(int i = 0; i < p.size(); i++)
{
if(p[i] == '0')
res += '%';
else if(p[i] == '1')
res += '@';
else if(p[i] == 'l')
res += 'L';
else if(p[i] == 'O')
res += 'o';
else
res += p[i];
}
return res;
}
int main()
{
int n;
cin >> n;
int flag = 0, res = 0;
vector<string> user, pass;
for(int i = 0; i < n; i++)
{
string a, b;
cin >> a >> b;
user.push_back(a);
if(check(b))
{
flag = 1;
pass.push_back(change(b));
res ++;
st[i] = true;
}else{
pass.push_back(b);
}
}
if(flag)
{
cout << res << endl;
for(int i = 0; i < n; i++)
if(st[i])
cout << user[i] << " " << pass[i] << endl;
}else{
if(n == 1 || n == 0)
cout << "There is " << n <<" account and no account is modified";
else
cout << "There are " << n <<" accounts and no account is modified";
}
return 0;
}
ACWING1520 男孩儿女孩
题目理解
模拟,性别然后每次成绩作比较,存储姓名和学号。这个算不恶心的。
代码实现
#include<iostream>
using namespace std;
bool flagM, flagF;
string nameM, nameF, numM, numF;
int scoreM = 110, scoreF = -1, n;
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
string name, sex, num;
int score;
cin >> name >> sex >> num >> score;
if(sex == "F")
{
if(score > scoreF)
{
nameF = name;
numF = num;
scoreF = score;
}
}else{
if(score < scoreM)
{
nameM = name;
numM = num;
scoreM = score;
}
}
}
if(scoreF == -1)
cout << "Absent" << endl;
else
cout << nameF << " " << numF << endl;
if(scoreM == 110)
cout << "Absent" << endl;
else
cout << nameM << " " << numM << endl;
if(scoreF == -1 || scoreM == 110)
cout << "NA";
else
cout << scoreF - scoreM;
return 0;
}
ACWING1534 字符串减法
题目理解
这个题简单,桶排思想存储B数组即可。
代码实现
#include<iostream>
#include<cstring>
using namespace std;
bool st[200];
string a, b;
int main()
{
getline(cin, a);
getline(cin, b);
for(int i = 0; i < b.size(); i++)
st[(int)b[i]] = true;
for(int i = 0; i < a.size(); i++)
if(!st[(int)a[i]])
cout << a[i];
return 0;
}
ACWING1557 说话方式
题目理解
这个题先用getline()
全读进来,然后一个一个字符判断,因为存在断位的地方是特殊字符的情况,所以对于每一个字符进行check
函数的判断即可。然后再将其放进map
求出现次数最多的。
代码实现
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
using namespace std;
vector<string> q;
unordered_map<string, int> map;
bool check(char s)
{
if(s >= 'a' && s <= 'z' || s >= 'A' && s <= 'Z' || s >= '0' && s <= '9')
return true;
return false;
}
char to_lower(char s)
{
if(s >= 'A' && s <= 'Z')
return (char)((int)s + 32);
return s;
}
int main()
{
string k;
getline(cin, k);
for(int i = 0; i < k.size(); i++)
{
string p = "";
while(check(k[i]))
{
p += to_lower(k[i]);
i++;
}
if(p != "")
{
q.push_back(p);
map[p] = 0;
}
}
sort(q.begin(), q.end());
int res= 0;
string ss;
for(int i = 0; i < q.size(); i++)
{
map[q[i]]++;
if(map[q[i]] > res)
{
ss = q[i];
res = map[q[i]];
}
}
cout << ss << " " <<res;
return 0;
}
ACWING1547 约会
题目理解
这个,写了20分钟,主要是凤凰传奇的光芒太好听了。这个题的坑是,要考虑到每个字符,题目上说的很清楚:B
题目
- 第一个相同字符只能是
A
~G
- 第二个只能是
0
`9`或`A`N
确定这两个才能AC不然就被SF搞了。
代码实现
#include<iostream>
using namespace std;
const int N = 10;
string wochen[] = {"", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
int main()
{
string s1, s2, s3, s4;
cin >> s1 >> s2 >> s3 >> s4;
char w, h;
int flag = 0;
for(int i = 0; i < s1.size() && i < s2.size(); i++)
{
if(s1[i] == s2[i] && s1[i] >= 'A' && s1[i] <= 'G' && flag == 0)
{
if(flag == 0)
{
w = s1[i];
flag = 1;
}
}else if(flag == 1 && s1[i] == s2[i] && (s1[i] >= 'A' && s1[i] <= 'N' || s1[i] >= '0' && s1[i] <= '9')){
h = s1[i];
break;
}
}
int p = 0;
for(int i = 0; i < s3.size() && i < s4.size(); i++)
if(s3[i] == s4[i] && (s3[i] >= 'a' && s3[i] <= 'z' || s3[i] >= 'A' && s3[i] <= 'Z' ))
{
p = i;
break;
}
cout << wochen[((int)(w) - 64)] << " ";
// 输出小时
if(h >= 'A' && h <= 'Z')
printf("%02d:", 9 + (int)(h) - 64);
else
printf("%02d:",(int)(h) - 48);
printf("%02d", p);
return 0;
}
标签:道题,string,int,res,cin,受制,&&,70,include
From: https://www.cnblogs.com/wxzcch/p/17703697.html