PAT基础编程题目-7-19 支票面额
PAT基础编程题目-7-19 支票面额
题目详情
解答
C语言版
#include<stdio.h>
int main() {
int y, f, n;
scanf("%d", &n);
for (y = 0; y < 50; y++) {
for (f = 0; f < 100; f++) {
// 仔细读懂题目,可以推出下面的公式
if (98 * f - 199 * y - n == 0) {
printf("%d.%d", y, f);
return 0;
}
}
}
printf("No Solution");
return 0;
}
C++版
#include<iostream>
using namespace std;
int main() {
int y, f, n;
cin >> n;
for (y = 0; y < 50; y++) {
for (f = 0; f < 100; f++) {
if (98 * f - 199 * y - n == 0) {
cout << y << "." << f;
return 0;
}
}
}
cout << "No Solution";
return 0;
}
Java版
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
int y, f, n = 0;
Scanner scanner = new Scanner(System.in);
if (scanner.hasNext()) {
n = scanner.nextInt();
}
scanner.close();
for (y = 0; y < 50; y++) {
for (f = 0; f < 100; f++) {
if (98 * f - 199 * y - n == 0) {
System.out.println(y+"."+f);
return;
}
}
}
System.out.println("No Solution");
}
}
创作不易,喜欢的话加个关注点个赞,谢谢谢谢谢谢!