文章

1

粉丝

130

获赞

0

访问

1.7k

头像
一次遍历
CSUOJ SVIP
P1415 华中科技大学机试题
发布于2023年3月29日 14:55
阅读数 1.7k

#include <iostream>
#include <string.h>
using namespace std;




int main(void){
    char str[105];
    while(cin >> str){
        int temp;
        int* p = new int[300];
        for(int i = 0; i < 300; i++) p[i] = -1;
        int* loc = new int[105];
        int* cnt = new int[300];
        for(int i = 0; i < 105; i++) loc[i] = -1;
        for(int i = 0; i < 300; i++) cnt[i] = -1;

        for (int i = strlen(str) - 1; i >= 0; i--){
            cnt[str[i]]++;
            loc[i] = p[str[i]];
            p[str[i]] = i;
        }
        for(int i = 0; i < 300; i++) p[i] = 0;

        for(int i = 0; i < strlen(str); i++){
            temp = i;

            if (p[i] || !cnt[str[i]]) continue;
            while(temp >= 0){
                if (loc[temp] == -1) cout << str[temp] << ":" << temp << endl;
                else cout << str[temp] << ":" << temp ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发