# C++程序设计实践一上（题目来自杭州电子科技大学ACM）

#### 题目一：2000.ASCLL码排序

Problem Description

Input

Output

#include<iostream>
using namespace std;
int main() {
char a, b, c;
while(cin >> a >> b >> c) {
if(a > b) {
swap(a, b); // 如果a的ASCII值大于b，交换a和b
}
if(a > c) {
swap(a, c); // 如果交换后a的ASCII值仍然大于c，交换a和c
}
if(b > c) {
swap(b, c); // 确保b的ASCII值不大于c
}
cout << a << " " << b << " " << c << endl;
}
return 0;
}

#### 题目二：2051.Bitset

Problem Description

Give you a number on base ten,you should output it on base two.(0 < n < 1000)

Input

For each case there is a postive number n on base ten, end of file.

Output

For each case output a number on base two.

#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
while(cin >> n)  {
if (n < 1 || n > 1000) {
return 1;
}
string s = "";
while (n > 0) {
s= to_string(n % 2) + s;
n /= 2;
}
cout << s<< endl;
}
return 0;
}

#### 题目三：2052.Picture

Problem Description

Give you the width and height of the rectangle,darw it.

Input

Input contains a number of test cases.For each case ,there are two numbers n and m (0 < n,m < 75)indicate the width and height of the rectangle.Iuput ends of EOF.

Output

For each case,you should draw a rectangle with the width and height giving in the input.

after each case, you should a blank line.

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int w, h;
while (cin >> w >> h) {
if (w <= 0 || h <= 0 || w > 75 || h > 75) {
continue;
}
cout << '+';
for (int i = 0; i < w ; ++i) {
cout << '-';
}
cout << '+' << endl;
for (int i = 0; i < h ; ++i) {
cout << '|';
for (int j = 0; j < w; ++j) {
if (j == 0 || j <= w ) {
cout << ' ';
}
else {
cout << '|';
}
}
cout << '|' << endl;
}
cout << '+';
for (int i = 0; i < w ; ++i) {
cout << '-';
}
cout << '+' << endl;
cout << endl;
}
return 0;
}

#### 题目四：2053.Switch Game

Problem Description

There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).

Input

Each test case contains only a number n ( 0< n<= 10^5) in a line.

Output

Output the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).

#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
while (cin >> n) {
int sqrt_n = sqrt(n);
// 由于可能存在精度问题，我们需要检查sqrt_n的平方是否等于n
if (sqrt_n * sqrt_n == n) {
// 如果是完全平方数，则第n个灯最终是开的
cout << 1 << endl;
}
else {
// 否则，第n个灯最终是关的
cout << 0 << endl;
}
}
return 0;
}

#### 题目五：2054.A= =B？

Problem Description

Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".

Input

each test case contains two numbers A and B.

Output

for each case, if A is equal to B, you should print "YES", or print "NO".

#include<iostream>
#include<string>
using namespace std;
void senre(string &a){
int temp=0;
if(a.find('.')!=a.npos){
while(*(a.end()-1-temp)=='0'){
temp++;
}
a.resize(a.size()-temp);
if(*(a.end()-1)=='.'){
a.resize(a.size()-1);
}
}
while(*(a.begin())=='0'){
a.erase(a.begin());
}
}
int main()
{
string a;
string b;
while(cin>>a>>b){
senre(a);
senre(b);
if(a==b){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
return 0;
}

|
21天前
|

21 1
|
24天前
|
C++
C++ : 程序设计简单实例
C++ : 程序设计简单实例
21 3
|
24天前
|

C++：程序设计实例
C++：程序设计实例
19 2
|
26天前
|
C++
C++解决线性代数矩阵转置 小实践
【6月更文挑战第3天】C++解决线性代数矩阵转置
20 2
|
1月前
|

32 1
|
1月前
|

C++课程设计实验杭州电子科技大学ACM题目（中）
C++课程设计实验杭州电子科技大学ACM题目（中）
17 1
|
16天前
|

11 0
|
17天前
|
C++

|
1月前
|

17 0
|
1月前
|

C++课程设计实验杭州电子科技大学ACM题目（下）
C++课程设计实验杭州电子科技大学ACM题目（下）
14 0