2021-08-14
Posted 李憨憨_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021-08-14相关的知识,希望对你有一定的参考价值。
练习一
OR62:倒置字符串
题目描述:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string str;
while(getline(cin, str))
{
reverse(str.begin(), str.end());
auto start = str.begin();
while(start != str.end())
{
auto end = start;
while(end != str.end() && *end != ' ')
end++;
reverse(start, end);
if(end != str.end())
start = end + 1;
else
start = end;
}
cout << str << endl;
}
return 0;
}
练习二
WY33计算糖果:
题目描述:
#include <iostream>
using namespace std;
int main()
{
int a, b, c, d;
cin >> a >> b >> c >> d;
int A = (a + c) / 2;
int B1 = (b + d) / 2;
int B2 = (c - a) / 2;
int C = d - B1;
if(B1 != B2)
cout << "No" << endl;
else
cout << A << " " << B1 << " " << C << endl;
return 0;
}
练习三
DD5进制转换
题目描述
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s, table = "0123456789ABCDEF";
int m,n;
cin >> m >> n;
bool flag = false;
if(m < 0)
{
m = 0 - m;
flag = true;
}
while(m)
{
s += table[m % n];
m /= n;
}
if(flag)
s += '-';
reverse(s.begin(), s.end());
cout << s << endl;
return 0;
}
以上是关于2021-08-14的主要内容,如果未能解决你的问题,请参考以下文章