int main() { FILE *fin=fopen("pprime.in","r"); FILE *fout=fopen("pprime.out","w"); int a,b,i,num; clock_t begin, end; double cost; begin = clock(); fscanf(fin,"%d %d",&a,&b); if((b-a)>500000) num=prime1(pnum,a,b); else{ num=prime2(pnum,a,b); start=0; } for (i = start; i < num ; i++){ if(pnum[i]>=a) if(ispal(pnum[i])) fprintf(fout,"%d\n",pnum[i]); } end = clock(); cost = (double)(end - begin) / CLOCKS_PER_SEC; printf("%lf seconds\n", cost); return 0; }
int main() { int p[8], i, j; while (gets(buf)) { memset(p, 0, sizeof(p)); p[1] = check1(); if (p[1]) { p[2] = ispal(s2); p[3] = check3(); p[4] = check4(); p[5] = check5(); p[6] = check6(); p[7] = check7(); } for (i = 1, j = 1; i <= 7; i++) { putchar(p[i] ? 'T' : 'F'); j &= p[i]; } printf(" The solution is %s\n", j ? "accepted" : "not accepted"); } return 0; }
main () { FILE *fin = fopen ("dualpal.in", "r"); FILE *fout = fopen ("dualpal.out", "w"); int an, as; int i,j,t,ok; char s[33]; fscanf (fin, "%d %d", &an, &as); t=0; for(i=as+1;;i++){ ok=0; for(j=2;j<=10;j++){ rnb(s,i,j); if(ispal(s)){ if(++ok>1)break; } } if(ok>1){ if(++t>an)break; fprintf (fout, "%d\n", i); } } exit (0); }
int main(void) { char t[20]; int i, base; int n,s; FILE *fin, *fout; fin = fopen("dualpal.in", "r"); fout = fopen("dualpal.out", "w"); assert(fin != NULL && fout != NULL); fscanf(fin, "%d %d", &n, &s); int get=0; for(i=s+1;get<n; i++) { int find=0; for (base=2;base<=10;base++) { numbconv(t, i, base); if(ispal(t)) { //printf("%s<%d> ", t, base); find++; } if (find > 1) { //printf("(%d)\n",i); get++; fprintf(fout,"%d\n",i); break; } } } exit(0); return 0; }
int main() { FILE *fin = fopen("calfflac.in", "r"); FILE *fout = fopen("calfflac.out", "w"); char str[20001]; char back[20001]; int index[20001]; int i, j, k, smallindex, largeindex; i = j = k = 0; while(fscanf(fin, "%c", &back[j++]) > 0){ if(back[j - 1] >= 'A' && back[j - 1] <= 'Z'){ index[i] = j -1; str[i] = back[j - 1] - 'A' + 'a'; i++; } else if(back[j - 1] >= 'a' && back[j - 1] <= 'z'){ index[i] = j - 1; str[i] = back[j - 1]; i++; } } str[i] = '\0'; int max = 0; for(i = 0; i < j; i++){ int temp; temp = ispal(str, i); if(temp > max){ max = temp; if(max % 2 == 1){ smallindex = i - max/2; largeindex = i + max/2; } else { smallindex = i - max/2 + 1; largeindex = i + max/2; } } } char re[2001]; for(i = index[smallindex]; i <= index[largeindex]; i++) re[i-index[smallindex]] = back[i]; re[i-index[smallindex]] = '\0'; fprintf(fout, "%d\n%s\n", max, re); fclose(fin); fclose(fout); }
int minCut(string s) { queue<int> node; node.push(0); int cuts = 0; //bfs vector<bool> visited(s.size(), false); while (true){ queue<int> tmp; while (!node.empty()){ int cur = node.front(); node.pop(); for (int i = s.size() - 1; i >= cur; i--){ if (visited[i]==false&&ispal(s, cur, i)){ if (i == s.size() - 1) return cuts; tmp.push(i+1); } } visited[cur] = true; } cuts++; node = tmp; } }
void solve(int n, int s) { char buff[17]; int i, base, npal; FILE *out; out = fopen("dualpal.out", "w"); while (n) { npal = 0; s++; for (npal = 0, base = 2; base <= 10; base++) { convert(s, base, buff); if (ispal(buff)) npal++; if (npal >= 2) { break; } } if (npal >= 2) { fprintf(out, "%d\n", s); n--; } } fclose(out); }
int main(){ char s[100],ans[100],ans2[100]; int i,k=0,r; scanf("%s",s); if(ispal(s)){ for(i=0;i<strlen(s)/2;i++){ ans[i]=s[i]; } ans[i]=s[i];i++; for(;i<strlen(s)+1;i++){ ans[i]=s[i-1]; } ans[i]='\0'; } else{ k=strlen(s); for(i=0;i<k;i++){ if(s[i]!=s[k-i-1]){ if(s[i+1]==s[k-i-1]){ for(r=0;r<k-i;r++){ ans2[r]=s[r]; } ans2[r++]=s[i]; ans2[k+1]='\0'; for(;r<=k;r++){ ans2[r]=s[r-1]; } break; } else if(s[i]==s[k-i-2]){ for(r=0;r<i;r++){ ans2[r]=s[r]; } ans2[r]=s[k-i-1];r++; for(;i<=k;i++,r++){ ans2[r]=s[i]; } break; } else{ ans2[0] = 'N'; ans2[1] = 'A'; ans2[2] = '\0'; break; } } } for(i=0;i<k;i++){ if(s[i]!=s[k-i-1]){ if(s[i]==s[k-i-2]){ for(r=0;r<i;r++){ ans[r]=s[r]; } ans[r]=s[k-i-1];r++; for(;i<=k;i++,r++){ ans[r]=s[i]; } break; } else if(s[i+1]==s[k-i-1]){ for(r=0;r<k-i;r++){ ans[r]=s[r]; } ans[r++]=s[i]; ans[k+1]='\0'; for(;r<=k;r++){ ans[r]=s[r-1]; } break; } else{ ans[0] = 'N'; ans[1] = 'A'; ans[2] = '\0'; break; } } } if(ispal(ans2)){ for(i=0;i<=strlen(ans2);i++){ ans[i]=ans2[i]; } } } if(ispal(ans)==0){ ans[0] = 'N'; ans[1] = 'A'; ans[2] = '\0'; } printf("%s",ans); return 0; }