Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 怎么控制输入的格式，我的输入需要用会车来停止，所以输入的格式就不对了，请知道的指点以下

Posted by tcxgsy at 2005-11-13 09:27:54 on Problem 2685
```#include"iostream.h"
#include"string.h"
#include"stdio.h"
#include"math.h"
int change1(char w)
{
switch(w)
{ case 'm' :return 1000;
case 'c' :return 100;
case 'x' : return 10;
case 'i' : return 1;
}
}
char chang2(int i)
{
switch(i)
{ case 0 :return 'i';
case 1 :return 'x';
case 2 : return 'c';
case 3 :return 'm';
}
}

int main()
{ char a[20];
char b[20];
// char o[30];
int n,i,sum1,sum2,len_a,len_b;

cin>>n;
while(n>0)
{ //cin>>a;cin>>b;
gets(a);
gets(b);

len_a=strlen(a);
len_b=strlen(b);
sum1=sum2=0;
for(i=0;i<len_a;i++)
{ if(a[i]>59)
sum1+=change1(a[i]);
else
{ sum1+=(a[i]-'0')*change1(a[i+1]);
i++;
}
}
for(i=0;i<len_b;i++)
{ if(b[i]>59)
sum2+=change1(b[i]);
else
{ sum2+=(b[i]-'0')*change1(b[i+1]);
i++;
}
}
sum1+=sum2;
for(i=3;i>=0;i--)
{ int k=sum1/pow(10,i);
sum1%=(int)pow(10,i);
if(k!=0)
if(k==1) cout<<chang2(i);
else cout<<k<<chang2(i);
}
cout<<endl;
n--;
}
return 1;
}```

Followed by: