알고리즘 연습/코드업
[C++][기초 - 종합]1080~1092
_h.j
2020. 9. 4. 15:32
728x90
[1080] 입력한 수보다 누적 합이 같거나 커졌을 때, 마지막으로 더한 정수 출력
#include <bits/stdc++.h>
using namespace std;
int main(){
int cut,n=0,sum=0;
cin >>cut;
while(sum<cut){
sum += (++n);
}
cout<<n;
return 0;
}
n++으로 하면 X
[1082]16진수 구구단
#include <bits/stdc++.h>
using namespace std;
int main(){
int n=0;
scanf("%X",&n);
for(int i = 0x1 ; i <=0xF;i++){
printf("%X*%X=%X\n",n,i,i*n);
}
return 0;
}
[1085]
#include <bits/stdc++.h>
using namespace std;
int main(){
float h,b,c,s;
cin >>h>>b>>c>>s;
printf("%.1f MB", ((h*b*c*s)/(8*1024*1024 ) ) );
return 0;
}
- 출력할때 계산되는 식이면 () 괄호로 꼭 묶어주기. 왜인지는 모르겠지만 묶지 않으면 이상한 수가 출력된다.
- 드디어 앞에서 쓴 것 활용. 소숫점 2번째 자리에서 반올림해 첫 번째 자리까지 출력
=> .1f
- 데이터 단위
8 bit = 1 byte
1024 byte = 1KB
1024 KB = 1 MB
1024 MB = 1GB
1024 GB = 1TB
[1087] 1080과 유사
#include <bits/stdc++.h>
using namespace std;
int main(){
int limit,sum=0,n=0;
cin>> limit;
while(sum< limit){
sum+= ++n;
}
cout<< sum;
return 0;
}
[1092]
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,day=1;
cin>> a>>b>>c;
while( (day %a !=0) || (day %b!=0) || (day % c!=0) )
day++;
cout<< day;
return 0;
}
비트 연산자 활용
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,day=1;
cin>> a>>b>>c;
while( (day %a ) | (day %b) | (day % c) )
day++;
cout<< day;
return 0;
}
728x90