Created
September 18, 2015 03:52
-
-
Save wildskyf/0542bd5a48c7a79204f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include <stdlib.h> | |
| #include <math.h> | |
| int main() | |
| { | |
| bool first = true; | |
| for (int times = 5 ; times > 0 ; times--) { | |
| int data_num = 0, a = 0,b = 0; | |
| int numArray[100]; | |
| scanf("%d",&data_num); | |
| for(int i = 0 ; i < data_num ; i++) { | |
| scanf("%d",&numArray[i]); | |
| } | |
| if(first) first=false; | |
| else printf("\n"); | |
| /* check is it correct */ | |
| bool correct = true; | |
| bool suf[data_num]; | |
| for(int i = 0 ; i < data_num-1 ; i++) { | |
| suf[abs(numArray[i+1]-numArray[i])-1] = true; | |
| } | |
| for(int i = 0 ; i < data_num-1 ; i++) { | |
| if (!suf[i]) | |
| { | |
| printf("INCORRECT\n"); | |
| correct = false; | |
| break; | |
| } | |
| } | |
| if(correct) { | |
| /* the first */ | |
| bool in = false; | |
| while(numArray[0]>10) | |
| { | |
| in = true; | |
| int sec = 0; | |
| for(int digit = 0;1;digit++) { | |
| if(((int)numArray[0]/((int)pow(10, digit)))%10 != 0 && numArray[0] / ((int)pow(10, digit)) > 0 ) { | |
| sec += ((int)numArray[0]/((int)pow(10, digit)))%10; | |
| } | |
| else { | |
| printf("%d", sec); | |
| break; | |
| } | |
| } | |
| numArray[0] = sec; | |
| } | |
| if(!in) printf("%d",numArray[0]); | |
| printf(" "); | |
| /* the second */ | |
| int sum = 0; | |
| int last = abs(numArray[data_num-1]); | |
| for(int i = 1 ; i <= last ; i++) { | |
| sum += pow(i,i); | |
| } | |
| printf("%d\n", sum%10); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment