考研408-数据结构(上机) --华中科技大学

3592. 矩阵转置 - AcWing题库

输入一个 𝑁×𝑁 的矩阵,将其转置后输出。

cpp 复制代码
#include<bits/stdc++.h>

using ll=long long;
using ari=std::array<int,3>;
using PII=std::pair<int,int>;

#define fir first
#define sec second

const int N=100+10;
const int mod=1e9+7;
const double eps=1e-6;

int n;
int g[N][N];
void solve()
{
	std::cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			std::cin>>g[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			std::swap(g[i][j],g[j][i]);
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			std::cout<<g[i][j]<<" ";
		}
		std::cout<<'\n';
	}
}
signed main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	
	int t=1;
	//std::cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

3593. 统计单词 - AcWing题库

编写一个程序,读入用户输入的,以 . 结尾的一行文字,统计一共有多少个单词,并分别输出每个单词含有多少个字符。 (凡是以一个或多个空格隔开的部分就为一个单词)

cpp 复制代码
#include<bits/stdc++.h>

using ll=long long;
using ari=std::array<int,3>;
using PII=std::pair<int,int>;

#define fir first
#define sec second

const int N=100+10;
const int mod=1e9+7;
const double eps=1e-6;

std::string s;
void solve()
{
	while(std::cin>>s)
	{
		if(s[s.length()-1]!='.') std::cout<<s.length()<<" ";
		else {
			std::cout<<s.length()-1<<" ";
			break;
		}
	}
}
signed main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	
	int t=1;
	//std::cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

3594. IP地址 - AcWing题库

输入一个 ip 地址串,判断是否合法。

一个合法的 ip 地址串,其形式为 a.b.c.d,其中 a,b,c,d𝑎,𝑏,𝑐,𝑑 都是 0∼2550∼255 的整数。

模拟题但是wa了好几发。。。

cpp 复制代码
#include<bits/stdc++.h>

using ll=long long;
using ari=std::array<int,3>;
using PII=std::pair<int,int>;

#define fir first
#define sec second

const int N=100+10;
const int mod=1e9+7;
const double eps=1e-6;

std::string s;
void solve()
{
	while(std::cin>>s)
	{
		int flag=1;
		int num=0;
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='.')
			{
				if(num>=0&&num<=255) num=0;
				else {
					flag=0;
					std::cout<<"No!\n";
					break;
				}
			}else if(s[i]>='0'&&s[i]<='9'){
				num=num*10+s[i]-'0';
			}else{
				flag=0;
				std::cout<<"No!\n";
				break;
			}
		}
		if(flag) 
		{
			if(num<0||num>255) std::cout<<"No!\n";
			else std::cout<<"Yes!\n";
		}
	}
}
signed main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	
	int t=1;
	//std::cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

有时间再补

相关推荐
延凡科技8 小时前
多场景落地复盘:端边云架构无人机智能巡检系统设计与实践
大数据·数据结构·人工智能·科技·架构·无人机·能源
皓月斯语14 小时前
B3842 [GESP202306 三级] 春游 题解
数据结构·c++·算法·题解
春日见14 小时前
算法与数据结构----哈希表
数据结构·人工智能·算法·机器学习·自动驾驶·哈希算法·散列表
萌动的小火苗15 小时前
嵌入式开发中的栈与队列:任务调度为什么依赖数据结构
数据结构·c++·单片机·嵌入式硬件
叩码以求索15 小时前
统计按位或能得到最大值的子集数目(一)
数据结构·算法
tachibana215 小时前
hot100 数组中的第K个最大元素(215)
java·数据结构·算法·leetcode
星恒随风15 小时前
C++ STL 栈详解:stack 的使用、经典题目与简单模拟实现
开发语言·数据结构·c++·笔记·学习
txzrxz16 小时前
单调队列讲解
数据结构·c++·算法·单调队列
Keven_1116 小时前
算法札记:树状数组的用途
数据结构·算法
cpp_250117 小时前
P1540 [NOIP 2010 提高组] 机器翻译
数据结构·c++·算法·队列·noip·洛谷题解