L1-1
cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
void solve()
{
cout << "Good code is its own best documentation." << endl;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}
L1-2
cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
int a, b;
void solve()
{
cin >> a >> b;
cout << a + b - 16 << endl;
cout << a + b - 3 << endl;
cout << a + b - 1 << endl;
cout << a + b << endl;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}
L1-3
cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
int n, m, k;
string x;
void solve()
{
cin >> n >> x >> m >> k;
if (k == n) cout << "mei you mai " << x << " de" << endl;
else if (k == m) cout << "kan dao le mai " << x << " de" << endl;
else cout << "wang le zhao mai " << x << " de" << endl;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}
L1-4
cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
int n;
void solve()
{
cin >> n;
while(n--)
{
int a,b,c;
cin >> a >> b >> c;
if (c == a * b) cout << "Lv Yan" << endl;
else if (c == a + b) cout << "Tu Dou" << endl;
else cout << "zhe du shi sha ya!" << endl;
}
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}
L1-5
cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
const int N = 110;
int n,m;
int a[N];
void solve()
{
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i];
cin >> m;
while(m--)
{
bool all_no = false;
bool wrong = false;
bool no_win =false;
for (int i = 1;i <= n;i++)
{
int x;
cin >> x;
if (x == a[i])
{
all_no = true;
no_win = true;
}
if (x + a[i] == 3)
{
wrong = true;
all_no = true;
}
}
if (wrong == false && no_win) cout << "Da Jiang!!!" << endl;
if (!all_no || wrong) cout << "Ai Ya" << endl;
}
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}
L1-6 (寄了)
s.substr(a,b),a是所截取的子串在原始字符串的起始位置,而b则是截取长度,不是子串的终止位置!
cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
const int N = 210;
string s;
string tp[N];
int n;
int a,b;
string s1,s2;
void solve()
{
cin >> s;
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> a >> b >> s1 >> s2;
tp[i] = s.substr(a - 1,b - 1);
s.erase(a - 1,b - 1); // 删除与截取一样[]
int st = s.find(s1);
int ed = s.find(s2);
// cout << st << endl;
// cout << ed << endl;
// cout << s << endl;
// s.insert((st + ed) / 2 + 1,tp[i]);
// cout << s << endl;
if (st == -1) //找不到返回-1
{
s.insert(s.size(),tp[i]); //在下标为s.size()处插入
// cout << s << endl;
}
else
{
s.insert((st + ed) / 2 + 1,tp[i]);
}
}
cout << s << endl;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}
改正后
cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
const int N = 210;
string s;
int n;
int a,b;
string s1,s2;
void solve()
{
cin >> s;
cin >> n;
while(n--)
{
cin >> a >> b >> s1 >> s2;
string s3 = s.substr(a - 1,b - a + 1); //开始下标,长度
s.erase(s.begin() + a - 1,s.begin() + b); // 删除[)
int len = s1.length();
string tmp = s1 + s2;
int pos = s.find(tmp);
if(pos != s.npos) s.insert(pos + len, s3); // 从下标pos + len 处插入 s3
else s.insert(s.length(), s3);
}
cout << s << endl;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}
L1-7 19分(wa了1分)
cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
const int N = 100010;
int n,m,s;
vector <int> a;
vector <int> b;
// map<int,PII> mp;
void solve()
{
cin >> n >> m>> s;
for (int i = 1;i <= n / i;i++)
{
if (n % i) continue;
a.push_back(i);
if (i != n / i) a.push_back(n / i);
}
sort(a.begin(),a.end());
a.erase(unique(a.begin(),a.end()),a.end());
// for (auto&t : a)
// cout << t << " ";
// cout << endl;
for (int i = 1;i <= m / i;i++)
{
if (m % i) continue;
b.push_back(i);
if (i != m / i) b.push_back(m / i);
}
sort(b.begin(),b.end());
b.erase(unique(b.begin(),b.end()),b.end());
// for (auto&t : b)
// cout << t << " ";
// cout << endl;
int minn = 1e9;
int tp1 = -1,tp2 = -1;
for (int i = 0;i < a.size();i++)
for (int j = 0;j < b.size();j++)
{
if ((n / a[i] + m / b[j]) == s)
{
if (abs(a[i] - b[j]) < minn)
{
minn = abs(a[i] - b[j]);
tp1 = n / a[i],tp2 = m / b[j];
}
// mp[abs(a[i] - b[j])] = {a[i],b[j]};
// printf("%d %d %d %d\n",a[i],n / a[i],b[j],m / b[j]);
}
}
if (tp1 == -1 && tp2 == -1) cout << "No Solution" << endl;
else
cout << tp1 << " " << tp2 << endl;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}