一、题目链接
http://noi.openjudge.cn/ch0105/08/
二、解题思路
◎ 以步长-1为基准,循环输入每个已知角的度数,并用其累减n边形的内角和度数;
◎ 循环结束后,剩余n边形的内角和度数就是未知角的度数。
三、实施步骤
◎ 首先,定义并输入int类型的整数n,代表n边形的边数;
◎ 其次,定义两个int类型的整数ans、t,分别代表未知角的度数、每个已知角的度数,初始时ans=(n-2)*180;
◎ 然后,通过整数n标记剩余角的个数,在n大于1时,步长为-1,循环处理如下:
→ 输入当前已知角的度数t;
→ 令ans=ans-t,n--;
上述循环结束后,ans中存储了未知角的度数;
◎ 最后,输出ans。
四、Java程序
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int t;
int ans = (n - 2) * 180;
while (n > 1) {
t = input.nextInt();
ans = ans - t;
n--;
}
System.out.print(ans);
}
}
五、C++程序
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int t;
int ans = (n - 2) * 180;
while (n > 1)
{
cin >> t;
ans = ans - t;
n--;
}
cout << ans;
return 0;
}