1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <iostream>#include <string>using namespace std;int main(){ int T; cin >> T; for(int i=1; i<=T; i++) { int cnt[10]={0}; char tc[2]; char alien_num[3]; int num; string s; cin >> tc >> num; cout << "#" << i << endl ; for(int j=0; j<num; j++) { cin >> alien_num; s=alien_num; if (!s.compare("ZRO")) cnt[0]++; else if (!s.compare("ONE")) cnt[1]++; else if (!s.compare("TWO")) cnt[2]++; else if (!s.compare("THR")) cnt[3]++; else if (!s.compare("FOR")) cnt[4]++; else if (!s.compare("FIV")) cnt[5]++; else if (!s.compare("SIX")) cnt[6]++; else if (!s.compare("SVN")) cnt[7]++; else if (!s.compare("EGT")) cnt[8]++; else if(!s.compare("NIN")) cnt[9]++; } //for(int j=0; j<10; j++) cout << "cnt["<<j<<"] : " << cnt[j] << endl; for(int j=0; j<10; j++) for(int k=0; k<cnt[j]; k++) { if(j==0) cout << "ZRO "; else if(j==1) cout << "ONE "; else if(j==2) cout << "TWO "; else if(j==3) cout << "THR "; else if(j==4) cout << "FOR "; else if(j==5) cout << "FIV "; else if(j==6) cout << "SIX "; else if(j==7) cout << "SVN "; else if(j==8) cout << "EGT "; else if(j==9) cout << "NIN "; } cout <<endl; }} |
char arr=="문자열" <- 이런 비교는 불가 string헤더 이용
string a = "I am string one! ;)";
string b = "string
if (a.compare(b) == 0) { // 두 문자열이 같을 때 }
else if (a.compare(b) < 0) { // a가 b보다 사전순으로 앞일 때 }
else if (a.compare(b) > 0) { // a가 b보다 사전순으로 뒤일 때 }
출처: http://makerj.tistory.com/127#string간의-문자열-비교 [CheatSheet]
문자인 숫자에 -'0'을 하면 정수가 되니까
이걸 이용한 다른 방법은 없을까?
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
| 171105_1228_암호문1 (0) | 2017.11.05 |
|---|---|
| 171104_1225_암호생성기 (0) | 2017.11.04 |
| 171103_1220_magnetic (0) | 2017.11.03 |
| 171103_거듭제곱 (0) | 2017.11.03 |
| 171103_14503_로봇청소기(틀림) (0) | 2017.11.03 |