# 17 条题解

• @ 2017-10-08 15:26:27

呜呜呜，第一次写这么多的代码，竟然re加wa，好受伤

``````#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<cmath>
#include<cstring>
#define maxa 200+10
#define FOR(i,x,y) for(i=x;i<=y;++i)
using namespace std;
void f(int x,int y,char ch,int z)
{
switch(ch)
{
case '+': x = y+z;
break;
case '-':x = y-z;
break;
case '*': x = y*z;
break;
case '/': x = y/z;
break;
case '^': x = pow(y,z);
break;
}
}
void swap1(int x,int y)
{
int t = x;
x = y;
y = t;
}
int main()
{
string s;
int n,p,q;
cin>>s;
cin>>n;
int len=  s.length();
p = q = 0;
int i,j;
FOR(i,0,len-1)
if(s[i]!='/')
{
p = p*10;
p+=s[i]-'0';
}
else
break;
FOR(j,i+1,len-1)
{
q = q*10;
q+=s[j]-'0';
}
int z,k;
FOR(i,1,n)
{
cin>>s;
int len = s.length();
if(s=="swap")
{
swap1(p,q);
}
else{
if(s.substr(0,5)=="feizi")
{
char ch = s[11];
if(s.substr(6,5)=="feizi")
{
if(s.substr(12,len-12)=="feizi")
z = p;
else if(s.substr(12,len-12)=="feimu")
z = q;
else
{
z = 0;
FOR(k,12,len-1)
{
z = z*10;
z+=s[k]-'0';
}
}
f(p,p,ch,z);
}
else
{
if(s.substr(12,len-12)=="feizi")
z = p;
else if(s.substr(12,len-12)=="feimu")
z = q;
else
{
z = 0;
FOR(k,12,len-1)
{
z = z*10;
z+=s[k]-'0';
}
}
f(p,q,ch,z);
}
}
else
{
char ch  = s[11];
if(s.substr(6,5)=="feizi")
{
if(s.substr(12,len-12)=="feizi")
z = p;
else if(s.substr(12,len-12)=="feimu")
z = q;
else
{
z = 0;
FOR(k,12,len-1)
{
z = z*10;
z+=s[k]-'0';
}
}
f(q,p,ch,z);
}
else
{
if(s.substr(12,len-12)=="feizi")
z = p;
else if(s.substr(12,len-12)=="feimu")
z = q;
else
{
z = 0;
FOR(k,12,len-1)
{
z = z*10;
z+=s[k]-'0';
}
}
f(q,q,ch,z);
}
}
}
}
cout<<p<<"/"<<q<<endl;
return 0;
}

``````
• @ 2016-11-14 17:19:51

python大法好,滑稽
```python fenzi,fenmu=raw_input().split('/'); fenzi=int(fenzi);fenmu=int(fenmu); n=int(raw_input()); comm=""; for i in range(0,n): s=raw_input(); s=s.replace("^","**"); s=s.replace("swap","fenzi+=fenmu;fenmu=fenzi-fenmu;fenzi-=fenmu"); s=s+";\nfenzi=abs(fenzi);fenmu=abs(fenmu);"; comm=comm+s; exec(comm); if fenmu==0: print "Error"; else : print "{}/{}".format(fenzi,fenmu); ```

• @ 2010-04-06 15:33:04

dfgdf

• @ 2009-11-01 22:51:27

我说啊，乘方的范围啊……

1/2

1

fenzi=fenzi^100000000000000000....【99个0省略】

没有超过范围吧，标程过得了吗？

• @ 2009-10-25 21:48:33

不一般地长。。。

• @ 2009-09-04 20:28:13

沙茶得不能再沙茶了！！！

PS:只要设最高位标志就能秒杀！另外，此题只有最朴素的高精会超时，只要再加一个优化都能AC！

• @ 2009-08-23 16:29:36

Ice=Is=1s?

• @ 2009-08-23 15:26:54

...

• @ 2009-08-20 20:26:59

果然是NC题口牙！

• @ 2009-08-19 20:14:57

要高精啊……

• @ 2009-08-19 22:02:30
• @ 2009-08-19 10:53:58

很难么……

• @ 2009-08-19 10:06:22

不愧是传说中的[red]SSS级魔兽[/red]瑙蚕

• @ 2009-08-19 08:12:25

貌似很简单啊?

• @ 2009-08-18 22:44:18

大家慢慢的用心敲撒。。。

• @ 2009-08-18 21:39:12

• @ 2009-08-18 21:01:25

chair

• 1

ID
1630

6

(无)

145

37

26%

1