544A - Set of Strings - CodeForces Solution


implementation strings *1100

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int k;
string ans[30], s;
int main()
{
    int cnt = 1, flag = 0, hash[400];
    cin >> k >> s;
    int len = s.length();
    memset(hash, 0, sizeof(hash));
    for (int i = 0; i < len; i++){
        if (!hash[s[i]]){
            hash[s[i]] = 1;
            ans[cnt++] += s[i];
        }
        else if (hash[s[i]] || s[i] == s[i - 1])
            ans[cnt - 1] += s[i];
        if (cnt == k + 1){
            for (int j = i + 1; j < len; j++)
                ans[cnt - 1] += s[j];
            flag = 1;
            break;
        }
    }
    if (!flag) {
        printf("NO\n");
    }
    else{
        printf("YES\n");
        for (int i = 1; i < cnt; i++)
            cout << ans[i] << endl;
    }
    return 0;
}
 				      	  					 						 	 		


Comments

Submit
0 Comments
More Questions

535B - Tavas and SaDDas
722C - Destroying Array
366A - Dima and Guards
716B - Complete the Word
1461C - Random Events
1627A - Not Shading
141B - Hopscotch
47B - Coins
1466C - Canine poetry
74A - Room Leader
1333D - Challenges in school №41
1475B - New Year's Number
461A - Appleman and Toastman
320B - Ping-Pong (Easy Version)
948A - Protect Sheep
387A - George and Sleep
53A - Autocomplete
1729G - Cut Substrings
805B - 3-palindrome
805C - Find Amir
676C - Vasya and String
1042B - Vitamins
1729F - Kirei and the Linear Function
25D - Roads not only in Berland
1694A - Creep
659F - Polycarp and Hay
1040A - Palindrome Dance
372A - Counting Kangaroos is Fun
1396B - Stoned Game
16A - Flag