计蒜客习题2:打印锯齿矩阵(vector)STL

问题描述
锯齿矩阵是指每一行包含的元素个数不相同的矩阵,比如: 
3 5 2 6 1 
2 3 4 
1 6 2 7 
读入若干对整数 (x,y),表示在第 x 行的末尾加上一个元素 y。输出最终的锯齿数组。初始时矩阵为空。 
输入格式 
第一行输入两个整数n,m(1≤n,m≤10000),其中 n 表示锯齿数组的行数,m 表示插入的元素总数。 
接下来一共 m 行,每行两个整数 x,y(1≤x≤n,0≤y≤10000),表示在第 x 行的末尾插入一个元素 y。 
输出格式 
一共输出 n 行,每行若干个用空格分隔的整数。如果某行没有任何元素,则输出一个空行。 
样例输入 
3 12 
1 3 
2 2 
2 3 
2 4 
3 1 
3 6 
1 5 
1 2 
1 6 
3 2 
3 7 
1 1 
样例输出 
3 5 2 6 1 
2 3 4 
1 6 2 7

#include<bits/stdc++.h>
using namespace std;
vector <int> mat[10004];
int main()
{
//	string s;
//	cin>>s;
//	printf("%d",((s[0]-'0')+(s[1]-'0'))*3);
//	
	
//	map<string,int> dict;
//	dict["tom"]= 1;
//	dict["mary"] = 3;
//	if(dict.count("mary")){
//		//dict["mary"] =5;
//		cout<<"EE:"<<dict["mary"]<<endl;
//	}
//	for(map<string,int>::iterator it=dict.begin();it!=dict.end();++it)
//	cout<<it->first<<"is in:"<<it->second<<endl;
//	dict.clear();
	int n,m,x,y;
	cin>>n>>m;
	for(int i=0;i<m;++i){
		cin>>x>>y;
		mat[x].push_back(y);
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=0;j<mat[i].size();j++)
		{
			if(j!= mat[i].size()-1)
			
			cout<<mat[i][j]<<" ";
			
			else	cout<<mat[i][j]<<endl;
		
		} 
		cout<<endl;
	}
	
	
	

	
//	set<string>  coutr;
//	coutr.insert("A");
//	coutr.insert("B");
//	coutr.insert("c");
//	set<string>::iterator it;
//	for(it=coutr.begin();it!=coutr.end();++it){
//		
//		cout<<*it<<" ";
//	}
//	cout<<endl;
//	coutr.erase("c");
//	if(coutr.count("A")){
//		
//		cout<<"c is in"<<endl;
//	}
	return 0;
 } 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值