Guest User

Untitled

a guest
Oct 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. main()
  5. {
  6. char num[100];
  7. int i=0, c=0, max=0;
  8. int a[10];
  9. for (i=0; i<10; i++) a[i]=0;
  10.  
  11. printf("請輸入數字:\n");
  12. scanf("%s", num);
  13.  
  14. for (i=0; i<strlen(num); i++) {
  15. c++;
  16. if (num[i] != num[i+1]) {
  17. if (c > a[num[i]-'0']) a[num[i]-'0']=c;
  18. if (c > max) max=c;
  19. c=0;
  20. }
  21. }
  22.  
  23. for (i=0; i<10; i++) if (a[i] == max) printf("%d連續出現%d次\n", i, max);
  24. }
Add Comment
Please, Sign In to add comment