%{
#include <stdio.h>
#include <math.h>
%}
DIGIT [0-9]
%%
{DIGIT}+ {
int num
= atoi
(yytext
); // Convert the matched string to an
integer int originalNum = num;
int numDigits = 0;
int sum = 0;
while (num > 0) {
num /= 10;
numDigits++;
}
num = originalNum; // Reset num to its original value
// Calculate the sum of digits raised to the power of the
number of digits
while (num > 0) {
int digit = num % 10;
sum += pow(digit, numDigits);
num /= 10;
}
if (sum == originalNum) {
printf("%s is an Armstrong number.\n", yytext);
} else {
printf("%s is not an Armstrong number.\n", yytext);
}
}
.|\n ; // Ignore any other characters
%%
int main() {
yylex();
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CiV9CgpESUdJVCBbMC05XQoKJSUKCntESUdJVH0rICAgIHsKICAgIGludCBudW0gPSBhdG9pKHl5dGV4dCk7IC8vIENvbnZlcnQgdGhlIG1hdGNoZWQgc3RyaW5nIHRvIGFuIGludGVnZXIKICAgIGludCBvcmlnaW5hbE51bSA9IG51bTsKICAgIGludCBudW1EaWdpdHMgPSAwOwogICAgaW50IHN1bSA9IDA7CiAgICAKICAgIC8vIENvdW50IHRoZSBudW1iZXIgb2YgZGlnaXRzCiAgICB3aGlsZSAobnVtID4gMCkgewogICAgICAgIG51bSAvPSAxMDsKICAgICAgICBudW1EaWdpdHMrKzsKICAgIH0KICAgIAogICAgbnVtID0gb3JpZ2luYWxOdW07IC8vIFJlc2V0IG51bSB0byBpdHMgb3JpZ2luYWwgdmFsdWUKICAgIAogICAgLy8gQ2FsY3VsYXRlIHRoZSBzdW0gb2YgZGlnaXRzIHJhaXNlZCB0byB0aGUgcG93ZXIgb2YgdGhlIG51bWJlciBvZiBkaWdpdHMKICAgIHdoaWxlIChudW0gPiAwKSB7CiAgICAgICAgaW50IGRpZ2l0ID0gbnVtICUgMTA7CiAgICAgICAgc3VtICs9IHBvdyhkaWdpdCwgbnVtRGlnaXRzKTsKICAgICAgICBudW0gLz0gMTA7CiAgICB9Ci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