题目1:
测试示例:
代码:
#define _author "Reskip"
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<cctype>
using namespace std;
bool datas[100005];
int pos[100005];
int beg;
char temp;
int main()
{
int tar = 0;
int posx = 0;
while (cin >> temp)
{
posx++;
if (temp == '(')
{
datas[beg] = 1;
pos[beg] = posx;
beg++;
}
if (temp == ')')
{
if (beg&&datas[beg - 1] == 1)
{
cout << pos[beg-1] << " " << posx << "\n";
beg--;
}
else
{
tar = 1;
}
}
if (temp == '[')
{
datas[beg] = 0;
pos[beg] = posx;
beg++;
}
if (temp == ']')
{
if (beg&&datas[beg - 1] == 0)
{
cout << pos[beg-1] << " " << posx << "\n";
beg--;
}
else
{
tar = 1;
}
}
}
if (beg || tar)
{
cout << "Match false!\n";
}
else
{
cout << "Match succeed!\n";
}
return 0;
}
题目2:
输入输出格式:
输入:
第1个稀疏矩阵的行数、
列数、
非零元个数(三个数都大于0)、
三元组
第2个稀疏矩阵的行数、
列数、
非零元个数(三个数都大于0)、
三元组 、
以行为主序输入稀疏矩阵三元组表
输出:
乘积矩阵的行数、
列数、
非零元个数(三个数都大于0)、
三元组
代码:
#define _author "Reskip"
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<sstream>
using namespace std;
struct table{
int x, y, val;
}d1[105], d2[105], ans[10005];
int cmp(table a, table b)
{
if (a.x != b.x)
{
return a.x < b.x;
}
return a.y < b.y;
}
int col, rol;
int main()
{
int n, m;
int drop;
cin >> col >> drop;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> d1[i].x >> d1[i].y >> d1[i].val;
}
cin >> drop >> rol;
cin >> m;
for (int i = 0; i < m; i++)
{
cin >> d2[i].x >> d2[i].y >> d2[i].val;
}
int beg = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (d1[i].y == d2[j].x)
{
ans[beg].x = d1[i].x;
ans[beg].y = d2[j].y;
ans[beg].val = d1[i].val*d2[j].val;
beg++;
}
}
}
sort(ans, ans + beg, cmp);
for (int i = 1; i < beg; i++)
{
if (ans[i].x == ans[i - 1].x&&ans[i].y == ans[i - 1].y)
{
ans[i].val += ans[i - 1].val;
ans[i - 1].val = 0;
}
}
int cnt = 0;
for (int i = 0; i < beg; i++)
{
if (ans[i].val)
{
cnt++;
}
}
cout << col << "\n" << rol << "\n" << cnt << "\n";
for (int i = 0; i < beg; i++)
{
if (ans[i].val)
{
cout << ans[i].x << "," << ans[i].y << "," << ans[i].val << "\n";
}
}
//system("pause");
}