首页 > 其他分享 >实验一

实验一

时间:2024-10-14 19:43:54浏览次数:6  
标签:case 3533340 num1 num2 int break 实验

代码一:
迭代器的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;}
![](/i/l/?n=24&i=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;
}
![](/i/l/?n=24&i=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;
	}
 }
![](/i/l/?n=24&i=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;
}

![](/i/l/?n=24&i=blog/3533340/202410/3533340-20241014194452980-1248835506.png) ![](/i/l/?n=24&i=blog/3533340/202410/3533340-20241014194502018-610601342.png)

标签:case,3533340,num1,num2,int,break,实验
From: https://www.cnblogs.com/cyuyan-xionger/p/18464838

相关文章

  • 实验1 现代C++编程初体验
    任务11//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参67#include<iostream>8#include<string>9#include......
  • 实验1 C++
    task1:1#include<iostream>2#include<string>3#include<vector>4#include<algorithm>56usingnamespacestd;78//声明9//模板函数声明10template<typenameT>11voidoutput(constT&c);1213//普通函数声明......
  • 实验一
    任务一:代码:#include<iostream>#include<string>#include<vector>#include<algorithm>usingnamespacestd;template<typenameT>voidoutput(constT&c);voidtest1();voidtest2();voidtest3();intmain(){ cout<......
  • 实验1现代c++编程初体验
    1.实验任务一task1.cpp//现代C++标准库、算法库体验//本例用到以下内容://1.字符串string,动态数组容器类vector、迭代器//2.算法库:反转元素次序、旋转元素//3.函数模板、const引用作为形参#include<iostream>#include<string>#include<vector>#include<......
  • 实验4-2-3-for 验证“哥德巴赫猜想C++解法
    #include<iostream>#include<cmath>boolvia(longlongi);usingnamespacestd;intmain(){  longlongn=0,i=3,p=0,q=0,a=0,b=0;  cin>>n;  if(n>4)  {    for(i=3;i<n/2;i+=2)    {......
  • 国防科大:反事实验证LLM在RAG的生成质量
    ......
  • 实验2
    任务1:源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13977#defineN24768#defineN321910intmain(){11intcnt;12intrandom_major,random_no;1314srand(t......
  • 【华三】【华三】VXLAN典型组网-集中式网关配置实验
    【华三】VXLAN典型组网-二层组网静态配置实验VXLAN的相关术语VTEP(VXLANTunnelEndPoint)VXLAN隧道核心设备VSI(VirtualSwitchInstance)VSIinterfaceVXLANsegmentVNI(VXLANNetworkIdentifier)AC(AttachmentCircuit)VXLAN隧道工作模式L2Gateway:二层转发模式IPGateway:......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1397#defineN2476#defineN321intmain(){intcnt;intrandom_major,random_no;srand(time(NULL));cnt=0;while(cnt<N){random......
  • 实验二
    task_1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1397#defineN2476#defineN321intmain(){intcnt;intrandom_major,random_no;srand(time(NULL));cnt=0;while(cnt<......