2022-03-20
L-1 打折
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
printf("%.2f",n*1.0 * m / 10);
}
L-2 情人节
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
int main()
{
string s;
int n = 0;
while (cin >> s,s!=".")
{
v.push_back(s);
n++;
}
if (v.size() > 13) cout << v[1] << " and " << v[13] << " are inviting you to dinner...";
else if (v.size() > 1) cout << v[1] << " is the only one for you...";
else cout << "Momo... No one is for you ...";
return 0;
}
L-3 IP地址转换
#include <bits/stdc++.h>
using namespace std;
int judge(string a)
{
int res = 0;
int num = 0;
for (int i = 0; i < a.size(); i++)
num = num * 10 + a[i] - '0';
int i = 0;
while (num)
{
int x = num % 10;
res += pow(2, i) * x;
i++;
num /= 10;
}
return res;
}
int main()
{
string s;
cin >> s;
string a = s.substr(0, 8);
string b = s.substr(8, 8);
string c = s.substr(16, 8);
string d = s.substr(24, 8);
printf("%d.%d.%d.%d", judge(a), judge(b), judge(c), judge(d));
}
L-4 凯撒密码
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
int cmp(string a)
{
int num = 0;
int f=1;
int start=0;
if(a[0]=='-')f=-1,start=1;
for (int i=start; i < a.size(); i++)
{
num = num * 10 + a[i] - '0';
}
return num*f;
}
int main()
{
string s;
while (cin >> s)v.push_back(s);
int n = cmp(v[(int)v.size() - 1]);
n%=26;
bool f = false;
for (int i = 0; i < v.size()-1; i++)
{
if (f)cout << ' ';
f = true;
for (int j = 0; j < v[i].size(); j++)
{
if (v[i][j] >= 'a' && v[i][j] <= 'z') printf("%c", ((v[i][j] - 'a') + n + 26) % 26 + 'a');
else if (v[i][j] >= 'A' && v[i][j] <= 'Z') printf("%c", ((v[i][j] - 'A') + n + 26) % 26 + 'A');
else printf("%c",v[i][j]);
}
}
return 0;
}
L-5 乘法口诀数列
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
int a, b;
cin >> a >> b >> n;
vector<int>v;
v.push_back(a);
v.push_back(b);
for (int i = 1; i < n; i++)
{
int x = v[i - 1] * v[i];
if (x >= 10)
{
v.push_back(x / 10);
v.push_back(x % 10);
}
else v.push_back(x);
}
for (int i = 0; i < n; i++)
{
cout << v[i] ;
if(i<n-1)cout<<' ';
}
return 0;
}
L-6 组个最小数
#include <bits/stdc++.h>
using namespace std;
vector<int>v;
int main()
{
for (int i = 0; i < 10; i++)
{
int x;
cin >> x;
for (int j = 0; j < x; j++)
v.push_back(i);
}
sort(v.begin(), v.end());
if (!v[0])
{
for (int i = 1; i < v.size(); i++)
{
if (v[i] != 0)
{
swap(v[0], v[i]);
break;
}
}
}
for (auto x : v)cout << x;
return 0;
}
M-1 出租
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str;
cin >> str;
set<int>s;
for (int i = 0; i < str.size(); i++)
s.insert(str[i] - '0');
cout << "int[] arr = new int[]{";
vector<int>v;
for (auto x : s)v.push_back(x);
for (int i = v.size() - 1; i >= 0; i--)
{
cout << v[i];
if (i > 0)cout << ',';
}
cout << "};" << endl;
cout << "int[] index = new int[]{";
reverse(v.begin(), v.end());
for (int i = 0; i < str.size(); i++)
{
for (int j = 0; j < v.size(); j++)
if (v[j] == str[i] - '0')cout << j;
if (i < str.size() - 1)cout << ",";
}
cout << "};";
return 0;
}
M-2 装箱问题
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N], b[N];
int n;
int main()
{
cin >> n;
int i, j, maxv = 0;
for (i = 0; i < n; i++)
cin>>a[i];
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (b[j] + a[i] <= 100)
{
b[j] += a[i];
printf("%d %d\n", a[i], j + 1);
if (maxv < j + 1)
maxv = j + 1;
break;
}
}
}
printf("%d", maxv);
return 0;
}
M-3 谷歌的招聘
#include <bits/stdc++.h>
#define int long long
using namespace std;
int L, K;
bool isprime(int x)
{
if (x < 2) return false;
for (int i = 2; i <= x / i; i++)
if (x % i == 0)
return false;
return true;
}
signed main()
{
cin >> L >> K;
string s;
cin >> s;
for (int i = 0; i + K -1< s.size(); i++)
{
int r = i + K - 1;
int num = 0;
for (int j = i; j <= r; j++)
{
num = num * 10 + s[j] - '0';
}
if (isprime(num))
{
for(int j=i;j<=r;j++)cout<<s[j];
exit(0);
}
}
cout << 404 << endl;
return 0;
}
M-4 梅森数
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
bool isprime(int x)
{
if (x < 2) return false;
for (int i = 2; i <= x / i; i++)
if (x % i == 0)
return false;
return true;
}
signed main()
{
cin >> n;
bool f=false;
for (int i = 2; i <= n; i++)
{
if (isprime(pow(2, i) - 1))
{
cout << pow(2, i) - 1 << endl;
f=true;
}
}
if(!f)puts("None");
return 0;
}
H-1 排座位
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int g[N][N];
int n, m, k;
bool check(int a, int b)
{
for (int i = 1; i <= n; i++)
if (g[a][i] == 1 && g[i][b] != 0)
return true;
return false;
}
int main()
{
cin >> n >> m >> k;
while (m--)
{
int a, b, c;
cin >> a >> b >> c;
g[a][b] = g[b][a] = c;
}
while (k--)
{
int a, b;
cin >> a >> b;
if (g[a][b] == 1)puts("No problem");
if (g[a][b] == 0)puts("OK");
if (g[a][b] == -1 && check(a, b))puts("OK but...");
else if (g[a][b] == -1)puts("No way");
}
return 0;
}
H-2 单身狗
#include <bits/stdc++.h>
using namespace std;
const int N = 50010;
map<int, int>mp;
unordered_map<int, int>st;
int n;
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
st[a] = b;
st[b] = a;
}
int m;
cin >> m;
for (int i = 0; i < m; i++)
{
int id;
cin >> id;
mp[id] = true;
}
bool f = false;
vector<int>v;
for (auto x : mp)
{
if (!st.count(x.first))
{
v.push_back(x.first);
continue;
}
if (!mp.count(st[x.first]))v.push_back(x.first);
}
cout << v.size() << endl;
for (auto x : v)
{
if (f)cout << ' ';
f = true;
printf("%05d",x);
}
}
|