Created
August 26, 2020 06:30
-
-
Save un-ro/6ac07f51be6065a401f7eb496b97c774 to your computer and use it in GitHub Desktop.
KMIPN 2020 Internal - JTI Polinema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CHARACTER PATTERN | |
| #include<iostream> | |
| int main(){ | |
| int t,l,c,j=0,i=0; | |
| scanf("%d",&t); | |
| while(t--){ | |
| scanf("%d %d",&l,&c); | |
| for(i=0;i<=(l*2);i++){ | |
| // KOLOM | |
| if(i%2==0){ | |
| for(j=0;j<=(c*3);j++) | |
| printf("*"); | |
| printf("\n"); | |
| } | |
| // BARIS | |
| if(i!=(l*2)){ | |
| for(j=0;j<=(c*3);j++){ | |
| // kelipatan 3 jadi * | |
| if(j%3==0) | |
| printf("*"); | |
| else | |
| printf("."); | |
| } | |
| } | |
| printf("\n"); | |
| } | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // PRIME1 | |
| #include<iostream> | |
| #include<math.h> | |
| bool isPrime (int angka){ | |
| if (angka <=1) | |
| return false; | |
| else if (angka == 2) | |
| return true; | |
| else if(angka % 2 == 0) | |
| return false; | |
| else { | |
| // Mengecheck angka dengan bilangan prima | |
| bool prime = true; | |
| int checkBagi = 3; | |
| int kuadratnum = sqrt(angka) +1; | |
| while (checkBagi <= kuadratnum){ | |
| if (angka % checkBagi == 0) | |
| return false; | |
| checkBagi +=2; | |
| } | |
| return prime; | |
| } | |
| } | |
| int main(){ | |
| int t, awal, akhir, i, j; | |
| scanf("%d",&t); | |
| for(i=0;i<t;i++){ | |
| scanf(" %d %d",&awal,&akhir); | |
| printf("\n"); | |
| for(j=awal;j<=akhir;j++){ | |
| if(isPrime(j)) | |
| printf("%d\n",j); | |
| } | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SUM OF DIGITS - ALCATRAZ1 | |
| #include <iostream> | |
| using namespace std; | |
| int main(){ | |
| int t; | |
| cin>>t; | |
| while(t--){ | |
| string s; | |
| cin>>s; | |
| long long sum=0; | |
| for(int i=0;i<s.length();i++){ | |
| sum+=(int)s[i]-'0'; | |
| } | |
| cout<<sum<<endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment