Untitled
unknown
c_cpp
a year ago
912 B
8
Indexable
//11635_Position
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char s[1000005] = {0};
int cnt[1000005] = {0};
int a[128][1000005];
int main(void)
{
int i, j;
scanf("%s", s);
int len = strlen(s);
for(i = 0;i<len;i++)
{
cnt[(int)s[i]]++; //該點出現的次數
a[(int)s[i]][cnt[(int)s[i]] - 1] = i; //值存於二為陣列 : a[ASCII][出現次數]
}
for(i = 0;i<128;i++) //判斷及印出該字元出現的位置
{
if(cnt[i]>0)
{
printf("%c:", i);
for(j = 0;j<cnt[i];j++) //最後一位不可空白,且要換行
{
if(j == cnt[i]-1)
printf("%d\n", a[i][j]);
else
printf("%d ", a[i][j]);
}
}
}
return 0;
}
Editor is loading...
Leave a Comment