238

# 题目

3 4 -5 2 6 1 -2 0

12 3 -10 1 6 0

# 代码

## C++解法

#include <iostream>
using namespace std;

int main() {
cin.tie(0);
cin.sync_with_stdio(false);

int a, n;
bool isFirst = true;
while (cin >> a >> n) {
if (n != 0) {
if (isFirst) {
isFirst = false;
} else {
cout << " ";
}
cout << a * n << " " << n - 1;
}
}
if (isFirst)
cout << "0 0";
cout << endl;
return 0;
}

## Python解法

import re
try:
while 1:
read += " " + input()
except:
pass

ans = []
for i in range(1, len(read), 2):
# print(a, n)
if n != 0:
ans += [a * n, n - 1]
if len(ans) == 0:
ans = [0, 0]
print(" ".join([str(i) for i in ans]))


## Java解法

import java.util.*;

class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
boolean isFirst = true;
while (in.hasNextInt()) {
int a = in.nextInt();
int n = in.nextInt();

if (n != 0) {
if (isFirst) {
isFirst = false;
} else {
System.out.print(" ");
}
System.out.printf("%d %d", a * n, n - 1);
}
}
if (isFirst){
System.out.print("0 0");
}
System.out.print("\n");

in.close();
}
}

• 点击查看/关闭被识别为广告的评论