알고리즘 연습/백준
[C++][BOJ- 10808/10820/1165/1166] islower, isupper,isdigit,isalpha , <string ,int,char>간 변환
_h.j
2021. 2. 16. 14:06
728x90
소스 코드 - 소문자 아스키
#include <bits/stdc++.h>
using namespace std;
int main(){
int i=0,alpha[26]={0,};
string word;
cin>>word;
// for(cin>>word ; word[i] ;) alpha[ word[i++]-'a']++;
// 위에 이렇게도 가능
for(auto c : word) alpha[c-'a']++;
for(auto e : alpha) cout<<e<<" ";
return 0;
}
소스 코드 - 함수 사용 안함
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
while(getline(cin,s)){
if(s=="") break;
int n[4]={0,};
for(char e : s){
if( e >= 'a' && e <= 'z' ) n[0]++;
else if(e >= 'A' && e <= 'Z' ) n[1]++;
else if( e >='0' && e<='9' ) n[2]++;
else n[3]++;
}
for(auto i : n)
cout<<i<<" ";
cout<<"\n";
}
return 0;
}
소스코드
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
getline(cin,s);
for(auto c : s){
if ( islower(c) ) cout<< char( (c - 'a' + 13)%26 + 'a') ;
else if ( isupper(c)) cout<< char((c - 'A' + 13)%26 + 'A');
else cout<<c;
}
return 0;
}
백준 접미사배열 11656
소스 코드
#include <bits/stdc++.h>
using namespace std;
// string to char* https://kwonkyo.tistory.com/285
// substr https://blockdmask.tistory.com/338
// deque https://blockdmask.tistory.com/73
int main(){
string s;
vector <string> v;
cin>>s;
for(int i = 0 ; s[i];i++)
v.push_back(s.substr(i));
sort(v.begin(),v.end());
for(auto e : v) cout<<e<<"\n";
return 0;
}
728x90