全部评论
While(cin>>x>>y>>z)这种形式就能ac了
循环输入样例
一直在跟0%作斗争,哭了
感觉试遍了所有方法😂还是0
什么情况,本地IDE一点问题木有啊 int main() { int x, y, z; cin >> x; cin >> y; cin >> z; int a, b, c; vector<vector<int>>A, B, C; vector<int> tmp1, tmp2, tmp3; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { cin >> a; tmp1.push_back(a); } A.push_back(tmp1); tmp1.clear(); } for (int i = 0; i < y; i++) { for (int j = 0; j < z; j++) { cin >> b; tmp2.push_back(b); } B.push_back(tmp2); tmp2.clear(); } for (int i = 0; i < x; i++) { for (int j = 0; j < z; j++) { int sum = 0; for (int m = 0; m < y; m++) { c = A[i][m] * B[m][j]; sum += c; } tmp3.push_back(sum); } C.push_back(tmp3); tmp3.clear(); } for (int i = 0; i < x; i++) { for (int j = 0; j < z - 1; j++) cout << C[i][j] << ' '; cout << C[i][z - 1]; cout << endl; } return 0; }
因为后台的测试用例是一次性输入多个用例,所以需要一个while循环
哭了
一个测试样例包含多组数据?
我也是……不知道怎么回事……😂哭了
我也是。。
+1,不知道是不是不喜欢python答题者,样例边界都考虑了,还是0% #coding=utf-8
import sys
if __name__ == "__main__":
m = int(sys.stdin.readline().strip())
n = int(sys.stdin.readline().strip())
t = int(sys.stdin.readline().strip())
if m == 0 or n == 0 or t == 0:
print(0)
x = [[0] * n for _ in range(m)]
y = [[0] * t for _ in range(n)]
ans = [[0] * t for _ in range(m)]
for i in range(m):
line = sys.stdin.readline().strip()
values = list(map(int, line.split()))
for j in range(len(values)):
x[i][j] = values[j]
for i in range(n):
line = sys.stdin.readline().strip()
value = list(map(int, line.split()))
for j in range(len(value)):
y[i][j] = value[j]
for i in range(m):
for j in range(t):
for k in range(n):
ans[i][j] += x[i][k] * y [k][j]
for i in range(m):
tmp = ''
for j in range(t):
tmp += str(ans[i][j])
tmp += ' '
print(tmp[:-1])
好像只要写那个函数就好了
c++ 一直0%.....
多组数据。。。我改到最后才看到😂
打印螺旋数输入与输出是怎么处理的呀?
螺旋数阵那个把我给看蒙了
螺旋数阵输入与输出是怎么处理的,有人知道吗?
同0,while也还是0
为啥想不开用python。。。c++很舒服啊 int r, k, c;
while(cin >> r >> k >> c){
int rr = r, kk = k, cc = c;
for (int i = 0; i < rr;i++)
for (int j = 0; j < kk;j++){
cin >> A[i][j];
}
for (int i = 0; i < kk;i++)
for (int j = 0; j < cc;j++){
cin >> B[i][j];
}
for (int i = 0; i < rr;i++)
for (int j = 0; j < cc;j++){
if(j!=0)
cout << " ";
int e = 0;
for (int u = 0; u < kk;u++){
e += A[i][u] * B[u][j];
}
cout << e;
if(j==cc-1){
cout << endl;
}
}
}
我也和你一样 但是不让我对
相关推荐
查看10道真题和解析
点赞 评论 收藏
分享