考研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;
}

有时间再补

相关推荐
AI情绪识别开源15 小时前
检信 ALLEMOTION OS 加密打包可执行程序 — 全面测试报告版本: v1.3功能测试 / 性能测试 /
开发语言·数据结构·人工智能·功能测试
伟大的车尔尼21 小时前
贪心的概念
数据结构·算法·贪心
AI情绪识别开源21 小时前
检信AI高一分班分科智选评估系统 v2.0测试报告
开发语言·数据结构·人工智能·科技
搜词研究员1 天前
# 德立教育和达德教育哪个好?学历提升选哪家?
考研·职场和发展·学习方法·高考
CoderYanger1 天前
A.每日一题:输入单词需要的最少按键次数 Ⅰ+Ⅱ
java·数据结构·算法·leetcode·面试
雪碧聊技术1 天前
KMP算法详解
数据结构
博界IT精灵1 天前
浮点数的表示--IEEE 754浮点数标准
考研
positive_zpc1 天前
进阶数据结构图——关键路径(四)
数据结构·图论·关键路径
孙克旭_1 天前
单链表进阶实操:5 道常考面试题详细解析【Java 实现】
java·开发语言·数据结构·单链表
唐维康1 天前
昆明理工891计算机考研真题:2022—2026五年完整收录整理
考研