http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=8192
這題我用java都返回值1不知道問題在哪用c就過了,不過字元陣列大小需設4不然會無效記憶體引用
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNext()) {
String str = scn.next(), s[] = str.split("");
int tot = 0, num = Integer.parseInt(str);
for (int i = 0; i < s.length; i++) {
tot += Integer.parseInt(s[i]) * Integer.parseInt(s[i]) * Integer.parseInt(s[i]);
}
if (tot == num)
System.out.println("1");
else
System.out.println("0");
}
}
/*
題目:[C_MM201-易] 立方和魔數
作者:1010
時間:西元 2016 年 7 月 */
}
#include<stdio.h>
#include<string.h>
int main(){
char s[4];
scanf("%s",s);
int num=atoi(s),i=0,n,tot=0;
for(i=0;i<strlen(s);i++){
n=s[i]-'0';
tot+=n*n*n;
}
if(num==tot)
printf("1\n");
else
printf("0\n");
/*
題目:[C_MM201-易] 立方和魔數
作者:1010
時間:西元 2016 年 7 月 */
}