代码一:
迭代器的v.end()是指容器最后一个元素的后面一个
代码二:
代码三:

点击查看代码
bool is_palindrome(std::string t) {
    int i = 0, j, flag = 0;
    j = t.size() - 1;
    for (; i < j; i++, j--)
    {
        if (t[i] != t[j]) flag = 1; break;
    }
    if (flag == 1) return false;
    if (flag == 0) return true;}
![](https://img2024.cnblogs.com/blog/3533340/202410/3533340-20241014170727898-228890469.png) 代码四:
点击查看代码
std::string dec2n(int x, int n) {
    std::string s,s0;
    int sum = 0;
    while (x) {
           s0=x % n+'0';
           s=s+s0;
           reverse(s.begin(), s.end());
           x = x / n;
    }
   return s;
}
![](https://img2024.cnblogs.com/blog/3533340/202410/3533340-20241014180125673-1292407551.png) 代码五:
点击查看代码
#include <iostream>
#include<iomanip>
using namespace std;
int main() {
	int i,j;
	char tou,x,y;
	cout << "  ";
	for (i = 0; i <= 25; i++)
	{
		x = 'a' + i;
		cout << setw(2) << x;
	}
	cout << endl;
	for (i = 1; i <= 25; i++) {
		tou = 'A' + i;
		cout << setw(2) << i<<setw(2)<<tou;
		for (j = 0; j < 25; j++) {
			tou = tou + 1;
			if (tou == 91) tou = 65;
			cout << setw(2) << tou;
		}
		cout << endl;
	}
	cout << 26;
	for (j = 0; j < 26; j++) {
		y = 'A' + j;
			cout << setw(2) << y;
	}
 }
![](https://img2024.cnblogs.com/blog/3533340/202410/3533340-20241014191525592-1989227834.png) 代码六:
点击查看代码
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
 
int main() {
    srand(time(0));
    double correctCount = 0;
    int t;
    for (int i = 0; i < 10; i++) {
        int num1 = rand()%10+1;
        int num2 = rand()%10+1;
        char op;
        switch (rand() % 4) {
            case 0: op = '+'; break;
            case 1:
            if(num2>num1){
                t=num2;
                num2=num1;
                num1=t;
            }
            op = '-'; break;
            case 2: op = '*'; break;
            case 3: op = '/'; do { num2 = rand() % 10 + 1; } while (num1 % num2 != 0); break;
        }
        std::cout << num1 << " " << op << " " << num2 << " = ";
        int userAnswer;
        std::cin >> userAnswer;
        int correctAnswer;
        switch (op) {
            case '+': correctAnswer = num1 + num2; break;
            case '-': correctAnswer = num1 - num2; break;
            case '*': correctAnswer = num1 * num2; break;
            case '/': correctAnswer = num1 / num2; break;
        }
        if (userAnswer == correctAnswer) {
            correctCount++;
        }
    }
    double accuracy = correctCount / 10 * 100;
    std::cout << "正确率:" << accuracy << "%";
    return 0;
}

![](https://img2024.cnblogs.com/blog/3533340/202410/3533340-20241014194452980-1248835506.png) ![](https://img2024.cnblogs.com/blog/3533340/202410/3533340-20241014194502018-610601342.png)
posted on 2024-10-14 19:47  熊二不晚安  阅读(4)  评论(0编辑  收藏  举报