본문 바로가기
  • Let's study

C++77

[백준] 30018: 타슈(C++) 문제https://www.acmicpc.net/problem/30018풀이a_i와 b_i의 차이를 모두 합해서 반으로 나눈 값을 구하면 된다.코드#include #include using namespace std;int main() { int n, a[101],b, cnt=0; cin>>n; for(int i=0;i>a[i]; } for(int i=0;i>b; cnt+=abs(a[i]-b); } cout 2026. 4. 5.
[백준] 10798: 세로 읽기(C++) 문제https://www.acmicpc.net/problem/10798풀이5개의 문자열을 입력받아 가장 긴 문자열의 길이를 기준으로 반복을 수행한다.이후 열 기준으로 순회하면서 각 문자열의 길이와 비교하여 해당 인덱스가 존재할 경우에만 문자를 출력한다.코드#include #include #include #include using namespace std;int main() { vectorv; string str; int mlen=0; for(int i=0;i>str; int size=str.size(); mlen=max(mlen,size); v.push_back(str); } for(int i=0;i=v[j].size()) continue; cout 2026. 3. 31.
[백준] 32722: Juta teekond(C++) 문제https://www.acmicpc.net/problem/32722코드#include using namespace std;int main() { int n[3]; for(int i=0;i>n[i]; } if (n[0] != 1 && n[0] != 3) { cout 2025. 12. 17.
[백준] 27240: Электричка(C++) 문제https://www.acmicpc.net/problem/27240풀이출발역 번호가 도착역 번호보다 클 수도 있다는 점을 생각해야 한다!코드#include using namespace std;int main() { int n, a, b, s, t; cin>>n>>a>>b; cin>>s>>t; if(s>a && sa && t=b && t>=b)) cout 2025. 12. 11.
[백준] 29267: Случай с игрой(C++) 문제https://www.acmicpc.net/problem/29267풀이변수를 저장된 탄약 수(saveCnt)와 현재 탄약 수(curCnt)로 나눠서 사용한다.saveCnt는 save에서만 변화되고, 나머지 입력에서는 curCnt가 변화된다.코드#include using namespace std;int main() { int n,k, saveCnt=0, curCnt=0; string str; cin>>n>>k; for(int i=0;i>str; if(str=="save") saveCnt=curCnt; else if(str=="load") curCnt=saveCnt; else if(str=="shoot") curCnt-=1; else curCnt+=k; .. 2025. 10. 29.
[백준] 20336: Haughty Cuisine(C++) 문제https://www.acmicpc.net/problem/20336풀이입력 받은 n개의 세트 메뉴 중에 아무거나 출력하면 되므로, 그냥 첫 번째 세트 메뉴의 개수와 메뉴를 출력하면 된다.코드#include #include using namespace std;int main() { int n, m; string str; cin>>n>>m; cout>str; cout 2025. 9. 23.