题解 | #找位置#

找位置

https://www.nowcoder.com/practice/e3b2cc44aa9b4851bdca89dd79c53150

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

int main() {
    string str;
    while (cin>>str) {
        bool flag[str.length()];
        for (int i = 0; i < str.length(); i++) {
            flag[i] = false;
        }
        for (int i = 0; i < str.length(); i++) {
            if (flag[i]) {
                continue;
            } else {
                flag[i]=true;
                vector<int> myVecto;
                myVecto.push_back(i);
                for (int j = i + 1; j < str.length(); j++) {
                    if (str[i] == str[j]) {
                        flag[j]=true;
                        myVecto.push_back(j);
                    }
                }
                if (myVecto.size() > 1) {
                    for (int k = 0; k < myVecto.size()-1; k++) {
                        cout << str[i] << ":" << myVecto[k]<<",";
                    }
                    cout<<str[i]<<":"<<myVecto[myVecto.size()-1]<<endl;
                }
            }

        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

考研复试机试 文章被收录于专栏

考研复试机试

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 12:22
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务