Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "nd.h"
- #include "nsd.h"
- int jeCislo(char ch) {
- if (ch >= '0' && ch <= '9') {
- return (1);
- }
- if (ch == ' ' || ch =='-') {
- // if (ch == ' ') {
- return (1);
- }
- return (0);
- }
- int main(int argc, char** argv) {
- char buf[256];
- while (fgets(buf, sizeof (buf), stdin)) {
- char cislo1[16];
- char cislo2[16];
- int mIndex = 0;
- int index = 0;
- int error =0;
- if(buf[0] == ' '){
- fprintf(stderr,"Wrong input.");
- continue;
- }
- while (buf[mIndex] != ' ') {
- // printf("prislo mi cislo: -%c-\n", buf[mIndex]);
- if (jeCislo(buf[mIndex]) == 0) {
- // printf("Wrong input : -%c-\n", buf[mIndex]);
- error++;
- break;
- }
- cislo1[index] = buf[mIndex];
- if(cislo1[index] == '-' && index!=0){
- error++;
- break;
- }
- index++;
- mIndex++;
- }
- cislo1[index] = '\0';
- // printf("%s\n", cislo1);
- mIndex++;
- int index2 =0;
- if(buf[mIndex] == ' ' || error>0){
- fprintf(stderr,"Wrong input.");
- continue;
- }
- if((buf[0] =='-' && buf[1] ==' ') || (buf[mIndex] == '-' && jeCislo(buf[mIndex+1])==0)){ //minus na zacatku
- fprintf(stderr,"Wrong input.");
- continue;
- }
- while(buf[mIndex] != '\n'){
- if(buf[mIndex]==' '){
- error++;
- break;
- }
- if (jeCislo(buf[mIndex]) == 0) {
- // printf("Wrong input2 : -%c-\n", buf[mIndex]);
- error++;
- break;
- }
- cislo2[index2] = buf[mIndex];
- if(cislo2[index2] == '-' && index2!=0){
- error++;
- break;
- }
- index2++;
- mIndex++;
- }
- cislo2[index2] = '\0';
- // printf("%s\n", cislo2);
- if(error >0 || (cislo2[0] - '0') == -48){
- fprintf(stderr,"Wrong input.");
- continue;
- }
- int number1;
- int number2;
- sscanf(cislo1, "%d", &number1);
- sscanf(cislo2, "%d", &number2);
- // printf("cisla jsou: %d a %d\n", number1, number2);
- if(number1 != 1 && number2 !=1 && nd(number1)==1 && nd(number2)==1){
- printf("prime\n");
- continue;
- }
- printf("%d\n", nsd(number1, number2));
- }
- fprintf(stderr,"DONE");
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement