hdu 1230 字符串
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <iostream>
#define MAX(a,b) a>b? a:b
using namespace std;
int in[30]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
/*http://acm.hdu.edu.cn/showproblem.php?pid=1230*/
int main()
{
char one[1000], two[100];
int one_seat[50], two_seat[50], three_seat[50];
int one_num, two_num;
memset(one, '\0', sizeof(one) );
memset(two, '\0', sizeof(two) );
while(~scanf("%s%s", one, two) )
{
char *p = one, *q = two;
one_num = two_num = 1;
memset(one_seat, 0, sizeof(one_seat) );
memset(two_seat, 0, sizeof(two_seat) );
memset(three_seat, 0, sizeof(three_seat) );
while(1)
{
while( (*p) == ',') p++;
if( (*p) != '\0')
{
one_seat[one_num++] = atoi(p);
while( (*p) != ',' && (*p) !='\0') {p++; if( (*p) =='\0') break; } p++;
}
else break;
}
while(1)
{
if( (*q) != '\0')
{
two_seat[two_num++] = atoi(q);
while( (*q) != ',' && (*q) != '\0') {q++; if( (*q) =='\0') break; } q++;
}
else break;
}
if(one_seat[1] + two_seat[1] == 0 && one_seat[2]+ two_seat[2] ==0) break;
int carry=0, seat=0;
for(int i= one_num-1, j= two_num-1; i>=0 || j>=0 || carry != 0; i--,j--)
{
if(i <= 0) i=0;
if(j <= 0) j=0;
three_seat[i] = (one_seat[i] + two_seat[j] +carry) % in[seat];
carry = (one_seat[i] + two_seat[j] + carry) / in[seat++];
}
int i=0;
while( three_seat[i] == 0)
i++;
for(; i<seat-1; i++)
printf("%d,", three_seat[i] );
printf("%d\n", three_seat[i]);
memset(one, '\0', sizeof(one) );
memset(two, '\0', sizeof(two) );
}
return 0;
}
附件列表