結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-08 10:19:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,282 bytes |
| コンパイル時間 | 701 ms |
| コンパイル使用メモリ | 71,564 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-12 23:25:34 |
| 合計ジャッジ時間 | 1,567 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 3 |
コンパイルメッセージ
main.cpp: In function ‘int calc(std::string)’:
main.cpp:14:13: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
14 | int a,b,f,x;
| ^
main.cpp:38:16: warning: ‘c’ may be used uninitialized in this function [-Wmaybe-uninitialized]
38 | } else if(c=='/'){
| ^~
main.cpp:33:12: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]
33 | x=a+b;
| ~^~~~
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int calc(string s){
if(s[0]<'0' || s[0]>'9'){
return 0;
} else if(s[s.size()-2]<'0' || s[s.size()-2]>'9'){
return 0;
}
int a,b,f,x;
f=0;
char c,c2;
string o,p;
for(int i=0; i<s.size(); ++i){
if(s[i]>='0' && s[i]<='9'){
if(f==0){
o+=s[i];
} else {
p+=s[i];
}
} else if(s[i]<'0' || s[i]>'9'){
if(s[i]=='='){
if(p.size()>1){
b=stoi(p);
} else {
b=p[0]-'0';
}
if(c=='+'){
x=a+b;
} else if(c=='-'){
x=a-b;
} else if(c=='*'){
x=a*b;
} else if(c=='/'){
x=a/b;
}
} else {
if(f==0){
if(o.size()>1){
a=stoi(o);
} else {
a=o[0]-'0';
}
o.clear();
c=s[i];
f=1;
} else {
if(p.size()>1){
b=stoi(p);
} else {
b=p[0]-'0';
}
p.clear();
if(c=='+'){
x=a+b;
} else if(c=='-'){
x=a-b;
} else if(c=='*'){
x=a*b;
} else if(c=='/'){
x=a/b;
}
a=x;
c=s[i];
}
}
}
}
return x;
}
int main(){
string s;
cin>>s;
int ss,se;
ss=-1;
vector<pair<int,int>> vp;
string s2;
s2=s;
s2+='=';
for(int i=0; i<s2.size(); ++i){
if(ss==-1 && s[i]>='0' && s[i]<='9'){
ss=i;
} else if(ss!=-1 && s[i]<'0' || s[i]>'9'){
se=i-1;
if(se-ss>0){
pair<int,int> p;
p=make_pair(ss,se);
vp.push_back(p);
}
ss=-1;
}
}
int x,y,z;
string o;
o=s;
o+='=';
x=calc(o);
z=x;
for(int i=0; i<vp.size(); ++i){
pair<int,int> pa;
pa=vp[i];
int l;
l=pa.second-pa.first;
for(int j=1; j<=l; ++j){
string o,o2;
o=s;
o2=s;
rotate(o.begin(),o.begin()+j,o.end());
o+='=';
y=calc(o);
if(y>z){
z=y;
}
rotate(o2.rbegin(),o2.rbegin()+j,o2.rend());
o2+='=';
y=calc(o2);
if(y>z){
z=y;
}
}
}
cout<<z<<endl;
return 0;
}