【C++程序设计实践】实验7

#include <bits/stdc++.h>
using namespace std;

int main() {
	char a[5000];
	scanf("%s", a);
	int n = strlen(a), t = 0;
	int i = 0, j = n - 1;
	n /= 2;
	while (t < n) {
		if (a[i] != a[j])
			break;
		t++;
		i++;
		j--;
	}
	if (t == n)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;


int main() {
	string str;
	int a[50] = {0};
	getline(cin, str);
	istringstream istrm(str);
	char ch;
	while (istrm >> ch) {
		if (ch >= 'a' && ch <= 'z')
			a[int(ch) - 96] += 1;
		else if (ch >= 'A' && ch <= 'Z')
			a[int(ch) - 64] += 1;
	}
	for (int i = 1; i <= 26; i++) {
		if (a[i] > 0)
			cout << char(i + 96) << ":" << a[i] << endl;
	}
	return 0;
}

 

#include <iostream>
#include <string>
using namespace std;

int main() {
	const int ARRAY_SIZE = 5;
	string str[ARRAY_SIZE];
	string max;
	for (int i = 0; i < ARRAY_SIZE; ++i) {
		getline(cin, str[i]);
		if (str[i] > max)
			max = str[i];
	}
	cout << max << endl;

	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	string strArray[5];
	for (int i = 0; i < 5; i++)
		getline(cin, strArray[i]);
	sort(strArray, strArray + 5);
	for (int j = 0; j < 5; j++) {
		cout << strArray[j] << endl;
	}
	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;


int main() {
	string line;
	string str[1000];
	int i = 0;
	string::size_type maxLength = 0;
	getline(cin, line);
	istringstream istrm(line);
	string word;
	while (istrm >> word) {
		str[i] = word;
		i++;
	}
	for (int j = 0; j < i; j++) {
		if (str[j].size() > maxLength)
			maxLength = str[j].size();
	}
	cout << maxLength << endl;
	return 0;
}

 

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
bool isAnagram(string str1, string str2);
int main() {
    string str1, str2;
    getline(cin, str1);
    getline(cin, str2);
    cout << boolalpha << isAnagram(str1, str2) << endl;
    return 0;
}
/* 请在下面编写isAnagram函数 */
bool isAnagram(string str1, string str2) {
	sort(str1.begin(), str1.end());
	sort(str2.begin(), str2.end());
	if (str1 == str2)
		return true;
	else
		return false;
}

 

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	string str;
	string str1;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++) {
		if (str[i] >= '0' && str[i] <= '9')
			str1 += str[i];
	}
	long int_atoi = atoi(str1.c_str());
	cout << int_atoi << endl;

	return 0;
}

 

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

int main() {
	string str;
	getline(cin, str);
	stringstream strm;
	int sum = 0;
	sum += 1 * (int(str[0]) - 48) + 2 * (int(str[2]) - 48) + 3 * (int(str[3]) - 48) + 4 * (int(str[4]) - 48) + 5 * (int(
	            str[6]) - 48) + 6 * (int(str[7]) - 48) + 7 * (int(str[8]) - 48) + 8 * (int(str[9]) - 48) + 9 * (int(str[10]) - 48);
	int ys = sum % 11;
	strm << ys;
	if (ys < 10) {
		if (strm.str() == str.substr(12, 1))
			cout << "Right" << endl;
		else
			cout << str.substr(0, 12) << strm.str() << endl;
	} else {
		if (88 == int(str[12]))
			cout << "Right" << endl;
		else
			cout << str.substr(0, 12) << "X" << endl;
	}

	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

int main() {
	string line;
	string str[1000];
	int i = 0;
	getline(cin, line);
	istringstream istrm(line);
	string word;
	while (istrm >> word) {
		str[i] = word;
		i++;
	}
	for (int j = 0; j < i; j++) {
		reverse(str[j].begin(), str[j].end());
		cout << str[j] <<" ";
	}

}

 【输入示例】

The C++ programming language is a general-purpose computer programming language originally developed in 1983.
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;


int main() {
	string str;
	int a[50] = {0};
	getline(cin, str);
	istringstream istrm(str);
	char ch;
	while (istrm >> ch) {
		if (ch >= 'a' && ch <= 'z')
			a[int(ch) - 96] += 1;
		else if (ch >= 'A' && ch <= 'Z')
			a[int(ch) - 64] += 1;
	}
	for (int i = 1; i <= 26; i++) {
		if (i == 1 || i == 5 || i == 9 || i == 15 || i == 21)
			cout << a[i] << " ";
	}
	return 0;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值