Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PHÂN SỐ
- #include<stdio.h>
- int UCLN(int a, int b){
- if(b==0){
- return a;
- } else {
- return UCLN(b,a%b);
- }
- }
- int BCNN(int a, int b){
- return (a*b/UCLN(a,b) );
- }
- struct PS{
- int TS;
- int MS;
- };
- int main(){
- int t,k;
- scanf("%d", &t);
- for(k = 1; k <= t; k++){
- struct PS psp, psq,pstong,psthuong;
- scanf("%d%d%d%d", &psp.TS, &psp.MS, &psq.TS, &psq.MS);
- int temp1=UCLN(psp.TS,psp.MS);
- int temp2=UCLN(psq.TS,psq.MS);
- psp.TS = psp.TS/temp1;
- psp.MS = psp.MS/temp1;
- psq.TS = psq.TS/temp2;
- psq.MS = psq.MS/temp2;
- int MSC = BCNN(psp.MS,psq.MS);
- psp.TS = (MSC/psp.MS)*psp.TS;
- psq.TS = (MSC/psq.MS)*psq.TS;
- psp.MS = MSC;
- psq.MS = MSC;
- printf("%s %s%d%s\n", "Case", "#",k,":");
- printf("%d%s%d %d%s%d\n", psp.TS,"/",psp.MS, psq.TS,"/",psq.MS);
- pstong.TS = psp.TS + psq.TS;
- pstong.MS = MSC;
- printf("%d%s%d\n", pstong.TS, "/", pstong.MS);
- psthuong.TS = psp.TS * psq.MS;
- psthuong.MS = psp.MS * psq.TS;
- int temp3 = UCLN(psthuong.TS, psthuong.MS);
- psthuong.TS=psthuong.TS/temp3;
- psthuong.MS=psthuong.MS/temp3;
- printf("%d%s%d\n", psthuong.TS, "/", psthuong.MS);
- }
- }
- //SẮP XẾP DANH SÁCH MẶT HÀNG
- #include<stdio.h>
- #include<string.h>
- struct MatHang{
- int MaMatHang;
- char TenMatHang[100];
- char NhomHang[100];
- float GiaMua;
- float GiaBan;
- };
- int main(){
- int SoMatHang, i,j;
- scanf("%d\n", &SoMatHang);
- struct MatHang mh[SoMatHang];
- for(i = 0; i < SoMatHang; i++){
- mh[i].MaMatHang = i+1;
- fflush(stdin);
- gets(mh[i].TenMatHang);
- fflush(stdin);
- gets(mh[i].NhomHang);
- scanf("%f", &mh[i].GiaMua);
- scanf("%f\n", &mh[i].GiaBan);
- }
- for(i = 0; i < SoMatHang; i++){
- for(j = i+1; j<SoMatHang; j++){
- if((mh[i].GiaBan-mh[i].GiaMua)<=(mh[j].GiaBan-mh[j].GiaMua)){
- struct MatHang tmp = mh[i];
- mh[i] = mh[j];
- mh[j] = tmp;
- }
- }
- }
- for(i = 0; i < SoMatHang; i++){
- printf("%d %s %s %.2f", mh[i].MaMatHang, mh[i].TenMatHang, mh[i].NhomHang,mh[i].GiaBan-mh[i].GiaMua);
- printf("\n");
- }
- }
- //TÌM THỦ KHOA CỦA KỲ THI
- #include<stdio.h>
- #include<string.h>
- struct ThiSinh{
- int MaThiSinh;
- char TenThiSinh[100];
- char NgayThangNamSinh[100];
- float DiemMon1;
- float DiemMon2;
- float DiemMon3;
- };
- int main(){
- int SoThiSinh,i,j;
- scanf("%d\n", &SoThiSinh);
- struct ThiSinh ts[SoThiSinh];
- for(i = 0; i<SoThiSinh; i++){
- ts[i].MaThiSinh = i+1;
- fflush(stdin);
- gets(ts[i].TenThiSinh);
- fflush(stdin);
- gets(ts[i].NgayThangNamSinh);
- scanf("%f", &ts[i].DiemMon1);
- scanf("%f", &ts[i].DiemMon2);
- scanf("%f\n", &ts[i].DiemMon3);
- }
- for(i = 0; i<SoThiSinh; i++){
- for(j = i+1; j<SoThiSinh; j++){
- if((ts[i].DiemMon1+ts[i].DiemMon2+ts[i].DiemMon3)<(ts[j].DiemMon1+ts[j].DiemMon2+ts[j].DiemMon3)){
- struct ThiSinh tmp = ts[i];
- ts[i] = ts[j];
- ts[j] = tmp;
- }
- if((ts[i].DiemMon1+ts[i].DiemMon2+ts[i].DiemMon3)==(ts[j].DiemMon1+ts[j].DiemMon2+ts[j].DiemMon3)){
- if(ts[i].MaThiSinh>ts[j].MaThiSinh){
- struct ThiSinh tmp2 = ts[i];
- ts[i] = ts[j];
- ts[j] = tmp2;
- }
- }
- }
- }
- float thukhoa = ts[0].DiemMon1+ts[0].DiemMon2+ts[0].DiemMon3;
- for(i = 0; i<SoThiSinh; i++){
- if((ts[i].DiemMon1+ts[i].DiemMon2+ts[i].DiemMon3)==thukhoa){
- printf("%d %s %s %.1f\n", ts[i].MaThiSinh, ts[i].TenThiSinh, ts[i].NgayThangNamSinh, ts[i].DiemMon1+ts[i].DiemMon2+ts[i].DiemMon3);
- }
- }
- }
- //SẮP XẾP THÍ SINH
- #include<stdio.h>
- #include<string.h>
- struct ThiSinh{
- int MaThiSinh;
- char TenThiSinh[100];
- char NgayThangNamSinh[100];
- float DiemMon1;
- float DiemMon2;
- float DiemMon3;
- };
- int main(){
- int SoThiSinh,i,j;
- scanf("%d\n", &SoThiSinh);
- struct ThiSinh ts[SoThiSinh];
- for(i = 0; i<SoThiSinh; i++){
- ts[i].MaThiSinh = i+1;
- fflush(stdin);
- gets(ts[i].TenThiSinh);
- fflush(stdin);
- gets(ts[i].NgayThangNamSinh);
- scanf("%f", &ts[i].DiemMon1);
- scanf("%f", &ts[i].DiemMon2);
- scanf("%f\n", &ts[i].DiemMon3);
- }
- for(i = 0; i<SoThiSinh; i++){
- for(j = i+1; j<SoThiSinh; j++){
- if((ts[i].DiemMon1+ts[i].DiemMon2+ts[i].DiemMon3)<(ts[j].DiemMon1+ts[j].DiemMon2+ts[j].DiemMon3)){
- struct ThiSinh tmp = ts[i];
- ts[i] = ts[j];
- ts[j] = tmp;
- }
- if((ts[i].DiemMon1+ts[i].DiemMon2+ts[i].DiemMon3)==(ts[j].DiemMon1+ts[j].DiemMon2+ts[j].DiemMon3)){
- if(ts[i].MaThiSinh>ts[j].MaThiSinh){
- struct ThiSinh tmp2 = ts[i];
- ts[i] = ts[j];
- ts[j] = tmp2;
- }
- }
- }
- }
- float thukhoa = ts[0].DiemMon1+ts[0].DiemMon2+ts[0].DiemMon3;
- for(i = 0; i<SoThiSinh; i++){
- printf("%d %s %s %.1f\n", ts[i].MaThiSinh, ts[i].TenThiSinh, ts[i].NgayThangNamSinh, ts[i].DiemMon1+ts[i].DiemMon2+ts[i].DiemMon3);
- }
- }
- //TIẾN HÓA POKEMON
- #include<stdio.h>
- #include<string.h>
- int Dem(int a, int b){
- int socon=0;
- while(b>=a){
- if((b-a)>=0){
- socon++;
- b = b - a + 2;
- }
- }
- return socon;
- }
- struct Pokemon{
- int mapokemon;
- char Ten[100];
- int sodacan;
- int sodaco;
- };
- int main(){
- int SoPokemon,i,j,tong=0;
- scanf("%d\n", &SoPokemon);
- struct Pokemon pk[SoPokemon];
- int temp[SoPokemon];
- for(i = 0; i<SoPokemon; i++){
- pk[i].mapokemon=i;
- fflush(stdin);
- gets(pk[i].Ten);
- scanf("%d%d\n", &pk[i].sodacan, &pk[i].sodaco);
- }
- for(i = 0; i<SoPokemon; i++){
- tong = tong + Dem(pk[i].sodacan,pk[i].sodaco);
- }
- for(i = 0; i < SoPokemon; i++){
- for(j = i+1; j<SoPokemon; j++){
- if(Dem(pk[i].sodacan,pk[i].sodaco)<Dem(pk[j].sodacan,pk[j].sodaco)){
- struct Pokemon temp = pk[i];
- pk[i] = pk[j];
- pk[j] = temp;
- }
- if(Dem(pk[i].sodacan,pk[i].sodaco)==Dem(pk[j].sodacan,pk[j].sodaco)){
- if(pk[i].mapokemon>pk[j].mapokemon){
- struct Pokemon temp2 = pk[i];
- pk[i] = pk[j];
- pk[j] = temp2;
- }
- }
- }
- }
- printf("%d\n", tong);
- printf("%s", pk[0].Ten);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement