5
10
#include <stdio.h>
#define MAX 10
bool isPrime(int n){
//判断是否是素数
bool flag = true;
if( n <=1) return false;
for(int i = 2; i*i <= n; i++){
if(n % i == 0){
flag = false;
break;
}
}
return flag;
}
int main(){
int res[MAX];
int sum,num,n,cnt;
cnt = 0;
while(scanf("%d",&n) != EOF && n != 0){
sum = 0;
for(int i = 0; i < n; i++){
scanf("%d",&num);
if(isPrime(num))
sum += num;
}
res[cnt++] = sum;
}
for(int i = 0; i < cnt; i++){
printf("%d\n",res[i]);
}
return 0;
}#include <stdio.h>
#include <string.h>
#define N 1000
char str[N];
char ans[N];
int main(){
while(scanf("%s",str) != EOF){
int len = strlen(str);
ans[0] = str[0];
int i = 1,j = 0,count = 1;
char pre = str[0];
while(1){
char tmp = str[i];
if(tmp != pre){
j++;
if(count >= 2)
ans[j++] = count+'0';
count = 1;
ans[j] = str[i++];
pre = tmp;
}else{
count++;
i++;
}
if(tmp == '\0')
break;
}
puts(ans);
printf("\n");
}
return 0;
}#include <stdio.h>
#define MAX 100
char buf[MAX][MAX];
bool mark[MAX][MAX];
int main(){
int m,n,sx,sy;
while(scanf("%d%d%d%d",&m,&n,&sx,&sy) != EOF){
if(m == 0 && n == 0)
break;
getchar();
for(int i = 0; i < m; i++){
scanf("%s",buf[i]);
getchar();
}
for( i = 0; i < m; i++){
for(int j = 0; j < n; j++)
mark[i][j] = false;
}
int count = 0;
while(1){
// printf("%d %d\n",sx,sy);
if(sx < 0 || sx > m-1 || sy < 0 || sy > n-1){
printf("%d\n",count);
break;
}
if(mark[sx][sy]){
printf("no\n");
break;
}
switch(buf[sx][sy]){
case 'W':mark[sx][sy] = true;sy--;count++;break;
case 'E':mark[sx][sy] = true;sy++;count++;break;
case 'S':mark[sx][sy] = true;sx++;count++;break;
case 'N':mark[sx][sy] = true;sx--;count++;break;
}
}
}
return 0;
}#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 1000
struct sts{
char no[30];
int num;
int score;
}stu[N];
bool cmp(sts A, sts B){
if(A.num != B.num)
return A.num > B.num;
if(A.score != B.score)
return A.score < B.score;
else{
int tmp = strcmp(A.no,B.no);
return tmp < 0;
}
}
int main(){
FILE *fp;
if((fp = fopen("Score.txt","r")) == NULL){
printf("Read file failed\n");
return -1;
}
int i = 0;
while(!feof(fp)){
fscanf(fp,"%s%d%d",stu[i].no,&stu[i].num,&stu[i].score);
i++;
}
sort(stu,stu+i,cmp);
for(int j = 0; j < i; j++)
printf("%s %d %d\n",stu[j].no,stu[j].num,stu[j].score);
fclose(fp);
return 0;
}原文地址:http://blog.csdn.net/u012027907/article/details/38283023