#include< bits/stdc++.h > using namespace std; | |
int main() { | |
int t; | |
string s; | |
cin >> t; | |
while(t--) { | |
int ar[256]= {0}; | |
cin >> s; | |
for(char ch : s){ | |
ar[ch]++; | |
} | |
for(char ch = 'a' ; ch <= 'z';ch++ ) { | |
if(ar[ch] > 0) cout << ch << " = " << ar[ch] << endl; | |
} | |
if(t>=1)cout << endl; | |
} | |
return 0; | |
} |
Showing posts with label String. Show all posts
Showing posts with label String. Show all posts
Sunday, October 13, 2019
Dimik oj - 15 - অক্ষর গণনা
Dimik oj - 16 - শব্দ বিপর্যয় python3 solution
test = int(input())
for i in range(test):
sentence = input().split(' ')
res = []
for x in sentence:
word = "".join(reversed(x))
res.append(word) #res.append(x[::-1])
print(' '.join(res))
Dimik oj - 14 অক্ষর গণনা python3 solution
if __name__ == '__main__':
n = int(input())
for i in range(n):
s = input().strip()
rs = sorted(list(set(s)))
for x in rs:
cnt = s.count(x)
print("%c = %d" %(x,cnt))
if i < n-1:
print()
n = int(input())
for i in range(n):
s = input().strip()
rs = sorted(list(set(s)))
for x in rs:
cnt = s.count(x)
print("%c = %d" %(x,cnt))
if i < n-1:
print()
Dimik oj - 14 অক্ষরের ঘনঘটা python3 solution
if __name__ == '__main__':
t = int(input())
for i in range(t):
s = input()
ch = input()
ans = s.count(ch)
if ans > 0:
print("Occurrence of '%c' in '%s' = %d" %(ch,s,ans))
else:
print("'%c' is not present"% ch)
Dimik oj - 14 অক্ষরের ঘনঘটা
#include < bits/stdc++.h >
using namespace std;
int main() {
int t;
string s;
char ch;
scanf("%d ",&t);
while(t--) {
getline(cin , s);
scanf("%c ",&ch);
size_t n = count(s.begin(), s.end(), ch);
if(n > 0){
cout << "Occurrence of " << "'" << ch <<"'" << " in '"
<< s << "' = " << n << endl;
}else {
cout << "'" << ch << "' is not present" << endl;
}
}
return 0;
}
Monday, September 16, 2019
Codeforce A. The Child and Homework
- #include< iostream >
- #include< cstdio >
- #include< algorithm >
- using namespace std;
- string o[4];
- int main() {
- int maxlength = 0, minlength = 110, maxindex = 0, minindex = 0;
- int c[4];
- for (int i = 0; i < 4; i++) {
- getline(cin, o[i]);
- c[i] = o[i].length() - 2;
- }
- sort(c, c + 4);
- bool hasMax = c[3] >= c[2] * 2;
- bool hasMin = c[0] <= c[1] / 2;
- if (hasMax == hasMin) {
- cout << "C";
- } else if (hasMin) {
- for (int i = 0; i < 4; i++) {
- if (c[0] + 2 == o[i].length()) {
- cout << o[i].at(0);
- }
- }
- } else if (hasMax) {
- for (int i = 0; i < 4; i++) {
- if (c[3] + 2 == o[i].length()) {
- cout << o[i].at(0);
- }
- }
- }
- return 0;
- }
Codeforce A. Soroban
- #include < bits/stdc++.h >
- using namespace std;
- int main()
- {
- int n;
- cin>>n;
- if(!n){
- cout<<"O-|-OOOO\n";
- return 0;
- }
- while(n){
- int m=n%10;
- n/=10;
- string s="--|OOOOO";
- if(m>=5)s[1]='O';
- else s[0]='O';
- s[m%5+3]='-';
- cout<<s<<endl;
- }
- }
Sunday, September 15, 2019
AtCoder Beginner Contest 136(B - Uneven Numbers)
- #include< bits/stdc++.h >
- using namespace std;
- int main(){
- int n, ans = 0;
- cin >> n;
- for(int i = 1; i <= n; i++) {
- string s;
- stringstream ss;
- ss << i;
- ss >> s;
- if(s.size()%2) ans++;
- }
- cout << ans << endl;
- return 0;
- }
Tuesday, September 19, 2017
Uri 2338 - Morse
#include < bits/stdc++.h >
using namespace std;
int main()
{
map < string , char > data;
data["=.==="] = 'a';
data["===.=.=.="] = 'b';
data["===.=.===.="] = 'c';
data["===.=.="] = 'd';
data["="] = 'e';
data["=.=.===.="] = 'f';
data["===.===.="] = 'g';
data["=.=.=.="] = 'h';
data["=.="] = 'i';
data["=.===.===.==="] = 'j';
data["===.=.==="] = 'k';
data["=.===.=.="] = 'l';
data["===.==="] = 'm';
data["===.="] = 'n';
data["===.===.==="] = 'o';
data["=.===.===.="] = 'p';
data["===.===.=.==="] = 'q';
data["=.===.="] = 'r';
data["=.=.="] = 's';
data["==="] = 't';
data["=.=.==="] = 'u';
data["=.=.=.==="] = 'v';
data["=.===.==="] = 'w';
data["===.=.=.==="] = 'x';
data["===.=.===.==="] = 'y';
data["===.===.=.="] = 'z';
data["===.===.===.===.==="] = '0';
data["=.===.===.===.==="] = '1';
data["=.=.===.===.==="] = '2';
data["=.=.=.===.==="] = '3';
data["=.=.=.=.==="] = '4';
data["=.=.=.=.="] = '5';
data["===.=.=.=.="] = '6';
data["===.===.=.=.="] = '7';
data["===.===.===.=.="] = '8';
data["===.===.===.===.="] = '9';
data["=.===.=.===.=.==="] = '.';
data["===.===.=.=.===.==="] = ',';
data["=.=.===.===.=.="] = '?';
data["=.===.===.===.===.="] = '\'';
data["===.=.===.=.===.==="] = '!';
data["===.=.=.===.="] = '/';
data["===.=.===.===.="] = '(';
data["===.=.===.===.=.==="] = ')';
data["=.===.=.=.="] = '&';
data["===.===.===.=.=.="] = ':';
data["===.=.===.=.===.="] = ';';
data["===.=.=.=.==="] = '=';
data["=.===.=.===.="] = '+';
data["===.=.=.=.=.==="] = '-';
data["=.=.===.===.=.==="] = '_';
data["=.===.=.=.===.="] = '"';
data["=.===.===.=.===.="] = '@';
string line;
int n,tc = 0;
cin >> n;
getline(cin,line);
while(n--){
if(tc != 0) cout << endl;
int dot = 0;
getline(cin,line);
string text;
for(int i = 0; i < line.size() ; i++ ){
if(line[i] == '.') dot++;
else{
if(dot == 3) text += " ";
else if(dot == 7) text += " ";
else if(dot == 1) text += '.';
text += line[i];
dot = 0;
}
}
line = text;
stringstream word;
word << line;
while(word >> line){
cout << data[line];
if(word.good()){
char ch = word.get();
ch = word.peek();
if(ch == ' ' ) cout << " " ;
}
}
cout << endl;
}
return 0;
}
using namespace std;
int main()
{
map < string , char > data;
data["=.==="] = 'a';
data["===.=.=.="] = 'b';
data["===.=.===.="] = 'c';
data["===.=.="] = 'd';
data["="] = 'e';
data["=.=.===.="] = 'f';
data["===.===.="] = 'g';
data["=.=.=.="] = 'h';
data["=.="] = 'i';
data["=.===.===.==="] = 'j';
data["===.=.==="] = 'k';
data["=.===.=.="] = 'l';
data["===.==="] = 'm';
data["===.="] = 'n';
data["===.===.==="] = 'o';
data["=.===.===.="] = 'p';
data["===.===.=.==="] = 'q';
data["=.===.="] = 'r';
data["=.=.="] = 's';
data["==="] = 't';
data["=.=.==="] = 'u';
data["=.=.=.==="] = 'v';
data["=.===.==="] = 'w';
data["===.=.=.==="] = 'x';
data["===.=.===.==="] = 'y';
data["===.===.=.="] = 'z';
data["===.===.===.===.==="] = '0';
data["=.===.===.===.==="] = '1';
data["=.=.===.===.==="] = '2';
data["=.=.=.===.==="] = '3';
data["=.=.=.=.==="] = '4';
data["=.=.=.=.="] = '5';
data["===.=.=.=.="] = '6';
data["===.===.=.=.="] = '7';
data["===.===.===.=.="] = '8';
data["===.===.===.===.="] = '9';
data["=.===.=.===.=.==="] = '.';
data["===.===.=.=.===.==="] = ',';
data["=.=.===.===.=.="] = '?';
data["=.===.===.===.===.="] = '\'';
data["===.=.===.=.===.==="] = '!';
data["===.=.=.===.="] = '/';
data["===.=.===.===.="] = '(';
data["===.=.===.===.=.==="] = ')';
data["=.===.=.=.="] = '&';
data["===.===.===.=.=.="] = ':';
data["===.=.===.=.===.="] = ';';
data["===.=.=.=.==="] = '=';
data["=.===.=.===.="] = '+';
data["===.=.=.=.=.==="] = '-';
data["=.=.===.===.=.==="] = '_';
data["=.===.=.=.===.="] = '"';
data["=.===.===.=.===.="] = '@';
string line;
int n,tc = 0;
cin >> n;
getline(cin,line);
while(n--){
if(tc != 0) cout << endl;
int dot = 0;
getline(cin,line);
string text;
for(int i = 0; i < line.size() ; i++ ){
if(line[i] == '.') dot++;
else{
if(dot == 3) text += " ";
else if(dot == 7) text += " ";
else if(dot == 1) text += '.';
text += line[i];
dot = 0;
}
}
line = text;
stringstream word;
word << line;
while(word >> line){
cout << data[line];
if(word.good()){
char ch = word.get();
ch = word.peek();
if(ch == ' ' ) cout << " " ;
}
}
cout << endl;
}
return 0;
}
Saturday, May 6, 2017
Uri 1667 - HTML
#include<bits/stdc++.h> |
using namespace std; |
int main() |
{ |
ios_base::sync_with_stdio(false);cin.tie(NULL); |
string s; |
char ch; |
while(scanf("%c",&ch)!=EOF){ |
s+=ch; |
} |
stringstream str1(s); |
vector < string > variable; |
string take; |
while (str1 >> take) |
variable.push_back(take); |
int len = 0; |
string sd; |
for(int i = 0; i < variable.size() ; i++){ |
bool b = true; |
sd = variable[i]; |
string st = (i != 0)? variable[i - 1] : sd ; |
if(len+sd.size() > 80 and sd != "< br >" and sd[sd.size()-1] != '.') { |
cout << endl, len = 0; |
}else if(len+sd.size()+1 > 80 and sd != "< br >" and sd[sd.size()-1] == '.'){ |
cout << endl, len = 0; |
} |
if(st[st.size()-1] == '.' and len > 75 and sd != "< br >"){ |
cout << endl, len = 0; |
} |
if(variable[i] == "< br >"){ |
cout << endl; |
len = 0,b=false; |
} |
else if(variable[i] == "< hr >") |
if(len!=0) cout << endl << "--------------------------------------------------------------------------------\n", len = 0,b = false; |
else cout << "--------------------------------------------------------------------------------\n",len = 0,b=false; |
else (i == 0 or len == 0)? cout << variable[i] : cout << " " << variable[i] ; |
if(b) len += sd.size()+1; |
} |
if(sd != "< br >")cout << endl; |
return 0; |
Monday, April 10, 2017
Uri 2248 - Internship
#include <bits/stdc++.h>
using namespace std;
struct ans{
int a = 0;
int b = 0;
}rec[1511];
bool cmp(const ans &x, const ans &y){
return x.b > y.b;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n ,m,k,l,ca = 0;
while(cin >> k and k){
for(int i = 0; i < k ;i++){
cin >> rec[i].a >> rec[i].b;
}
stable_sort(rec,rec+k,cmp);
cout << "Turma " << ++ca << endl;
bool b = true;
for( int i = 1 ;i < k ; i++){
if(b) cout << rec[i-1].a << " " ;
if(rec[i].b != rec[i-1].b and b) {
cout << endl ;
b = false;
}
rec[i-1].a = 0, rec[i-1].b = 0;
}
if(b) cout << rec[k-1].a << " " << endl;
rec[k].a = 0, rec[k].b = 0;
cout << endl ;
}
return 0;
}
using namespace std;
struct ans{
int a = 0;
int b = 0;
}rec[1511];
bool cmp(const ans &x, const ans &y){
return x.b > y.b;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n ,m,k,l,ca = 0;
while(cin >> k and k){
for(int i = 0; i < k ;i++){
cin >> rec[i].a >> rec[i].b;
}
stable_sort(rec,rec+k,cmp);
cout << "Turma " << ++ca << endl;
bool b = true;
for( int i = 1 ;i < k ; i++){
if(b) cout << rec[i-1].a << " " ;
if(rec[i].b != rec[i-1].b and b) {
cout << endl ;
b = false;
}
rec[i-1].a = 0, rec[i-1].b = 0;
}
if(b) cout << rec[k-1].a << " " << endl;
rec[k].a = 0, rec[k].b = 0;
cout << endl ;
}
return 0;
}
Sunday, April 9, 2017
Uri 1652 - Deli Deli
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,s1;
int n,k;
cin >> n >> k;
map < string , string > ans;
while(n--){
cin >> s >> s1;
ans.insert(pair < string , string > (s,s1));
}
while(k--){
cin >> s;
s1 = s;
if(ans.count(s) != 0)
cout << ans.find(s)->second << endl;
else{
if(s[s.size()-1] == 'y' and (s[s.size()-2] != 'a' and s[s.size()-2] != 'e' and s[s.size()-2] != 'i' and s[s.size()-2] != 'o' and s[s.size()-2] != 'u'))
s[s.size()-1] = 'i',s +="es";
else if(s[s.size()-1] == 'o' or (s[s.size()-1] == 's') or (s[s.size()-2] == 'c' and (s[s.size()-1] == 'h')) or (s[s.size()-2] == 's' and s[s.size()-1] == 'h') or (s[s.size()-1] == 'x'))
s += "es";
else
s += "s";
cout << s << endl;
ans.insert(pair(s1,s));
}
}
return 0;
}
using namespace std;
int main(){
string s,s1;
int n,k;
cin >> n >> k;
map < string , string > ans;
while(n--){
cin >> s >> s1;
ans.insert(pair < string , string > (s,s1));
}
while(k--){
cin >> s;
s1 = s;
if(ans.count(s) != 0)
cout << ans.find(s)->second << endl;
else{
if(s[s.size()-1] == 'y' and (s[s.size()-2] != 'a' and s[s.size()-2] != 'e' and s[s.size()-2] != 'i' and s[s.size()-2] != 'o' and s[s.size()-2] != 'u'))
s[s.size()-1] = 'i',s +="es";
else if(s[s.size()-1] == 'o' or (s[s.size()-1] == 's') or (s[s.size()-2] == 'c' and (s[s.size()-1] == 'h')) or (s[s.size()-2] == 's' and s[s.size()-1] == 'h') or (s[s.size()-1] == 'x'))
s += "es";
else
s += "s";
cout << s << endl;
ans.insert(pair
}
}
return 0;
}
Subscribe to:
Posts (Atom)