Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- main()
- {
- char num[100];
- int i=0, c=0, max=0;
- int a[10];
- for (i=0; i<10; i++) a[i]=0;
- printf("請輸入數字:\n");
- scanf("%s", num);
- for (i=0; i<strlen(num); i++) {
- c++;
- if (num[i] != num[i+1]) {
- if (c > a[num[i]-'0']) a[num[i]-'0']=c;
- if (c > max) max=c;
- c=0;
- }
- }
- for (i=0; i<10; i++) if (a[i] == max) printf("%d連續出現%d次\n", i, max);
- }
Add Comment
Please, Sign In to add comment