| @@ -0,0 +1,107 @@ | ||
| #include <iostream> | ||
| #include <cstdio> | ||
| #include <fstream> | ||
| using namespace std; | ||
| //ifstream fin("1520.in"); | ||
| char file[1000000]; | ||
| int filepos = 0; | ||
| char str[30000][15]; | ||
| int sz = 0; | ||
|
|
||
| bool isOp(char *p) { | ||
| if (*p == '+' || *p == '-' || *p == '(' || *p == ')') | ||
| return true; | ||
| else return false; | ||
| } | ||
|
|
||
| int getInt(char *p) { | ||
| int tmp = 0; | ||
| while (*p != '\0') { | ||
| tmp = tmp * 10 + (int) (*p - '0'); | ||
| ++p; | ||
| } | ||
| return tmp; | ||
| } | ||
|
|
||
| bool getInput(char *p) { | ||
| if (file[filepos] == '\0') return false; | ||
| if (isOp(file + filepos)) { | ||
| p[0] = *(file + filepos); | ||
| p[1] = '\0'; | ||
| filepos++; | ||
| } else if (!isOp(file + filepos)) { | ||
| for (int i = 0; file[filepos] != '\0' && file[filepos] >= '0' && file[filepos] <= '9'; ++i) { | ||
| p[i] = file[filepos]; | ||
| p[i + 1] = '\0'; | ||
| ++filepos; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| void copystr(char (*p)[15], char *input) { | ||
| for (int i = 0; i < 10; ++i) { | ||
| p[sz][i] = input[i]; | ||
| } | ||
| } | ||
|
|
||
| void setInt(int n) { | ||
| char a[10]; | ||
| int asz = 0; | ||
| str[sz - 1][0] = '0'; str[sz - 1][1] = '\0'; | ||
| while (n != 0) { | ||
| int tmp = n % 10; | ||
| a[asz++] = tmp + '0'; | ||
| n /= 10; | ||
| } | ||
| for (int i = 0; i < asz; ++i) { | ||
| str[sz - 1][i] = a[asz - 1 - i]; | ||
| } | ||
| } | ||
|
|
||
| int main() { | ||
| std::ios::sync_with_stdio(false); | ||
| char input[100]; | ||
| for (int i = 0; i < 1000000; ++i) { | ||
| char c = cin.get(); | ||
| while (c == ' ') c = cin.get(); | ||
| file[i] = c; | ||
| file[i + 1] = '\0'; | ||
| if (c == '\0' || c == EOF || c == '\n') { | ||
| file[i] = '\0'; | ||
| break; | ||
| } | ||
| } | ||
| while (getInput(input)) { | ||
| if (input[0] == '+' && (str[sz - 1][0] == '+' || str[sz - 1][0] == '(')) | ||
| continue; | ||
| if (!isOp(input)) { copystr(str, input); sz++; } | ||
| if (isOp(input)) { | ||
| if (input[0] == '+') { str[sz][0] = '+'; str[sz][1] = '\0'; ++sz; } //no sz - 1 | ||
| else if (input[0] == '-') { str[sz][0] = '-'; str[sz][1] = '\0'; ++sz; } | ||
| else if (input[0] == '(') { str[sz][0] = '('; str[sz][1] = '\0'; ++sz; } | ||
| else if (input[0] == ')') { | ||
| int tmp = 0; | ||
| while (str[sz - 1][0] != '(') { | ||
| if (sz >= 2 && str[sz - 2][0] == '(') { tmp += getInt(str[sz - 1]); sz -= 1; } | ||
| else if (sz >= 2 && str[sz - 2][0] == '+') { tmp += getInt(str[sz - 1]); sz -= 2; } | ||
| else if (sz >= 2 && str[sz - 2][0] == '-') { tmp -= getInt(str[sz - 1]); sz -= 2; } | ||
| } | ||
| setInt(tmp); | ||
| } | ||
| } | ||
| } | ||
| int sum = 0; | ||
| if (sz == 1) { | ||
| cout << str[0]; | ||
| return 0; | ||
| } | ||
| while (sz >= 1) { | ||
| if (sz == 1 && !isOp(str[0])) { sum += getInt(str[sz - 1]); break; } | ||
| else if (sz == 2 && str[0][0] == '-') { sum -= getInt(str[sz - 1]); break; } | ||
| else if (sz >= 2 && str[sz - 2][0] == '+') { sum += getInt(str[sz - 1]); sz -= 2; } | ||
| else if (sz >= 2 && str[sz - 2][0] == '-') { sum -= getInt(str[sz - 1]); sz -= 2; } | ||
| } | ||
| cout << sum; | ||
| return 0; | ||
| } |
| @@ -0,0 +1 @@ | ||
| (-1+2+(3+(-4+5))) |
| @@ -0,0 +1,86 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <ItemGroup Label="ProjectConfigurations"> | ||
| <ProjectConfiguration Include="Debug|Win32"> | ||
| <Configuration>Debug</Configuration> | ||
| <Platform>Win32</Platform> | ||
| </ProjectConfiguration> | ||
| <ProjectConfiguration Include="Release|Win32"> | ||
| <Configuration>Release</Configuration> | ||
| <Platform>Win32</Platform> | ||
| </ProjectConfiguration> | ||
| </ItemGroup> | ||
| <PropertyGroup Label="Globals"> | ||
| <ProjectGuid>{9C0BC7F6-7001-4D1A-9476-AF82EB1176DF}</ProjectGuid> | ||
| <Keyword>Win32Proj</Keyword> | ||
| <RootNamespace>My1520</RootNamespace> | ||
| </PropertyGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
| <ConfigurationType>Application</ConfigurationType> | ||
| <UseDebugLibraries>true</UseDebugLibraries> | ||
| <PlatformToolset>v120</PlatformToolset> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
| <ConfigurationType>Application</ConfigurationType> | ||
| <UseDebugLibraries>false</UseDebugLibraries> | ||
| <PlatformToolset>v120</PlatformToolset> | ||
| <WholeProgramOptimization>true</WholeProgramOptimization> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
| <ImportGroup Label="ExtensionSettings"> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <PropertyGroup Label="UserMacros" /> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <LinkIncremental>true</LinkIncremental> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <LinkIncremental>false</LinkIncremental> | ||
| </PropertyGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <ClCompile> | ||
| <PrecompiledHeader> | ||
| </PrecompiledHeader> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <Optimization>Disabled</Optimization> | ||
| <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| <SDLCheck>true</SDLCheck> | ||
| </ClCompile> | ||
| <Link> | ||
| <SubSystem>Console</SubSystem> | ||
| <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <ClCompile> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <PrecompiledHeader> | ||
| </PrecompiledHeader> | ||
| <Optimization>MaxSpeed</Optimization> | ||
| <FunctionLevelLinking>true</FunctionLevelLinking> | ||
| <IntrinsicFunctions>true</IntrinsicFunctions> | ||
| <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| <SDLCheck>true</SDLCheck> | ||
| </ClCompile> | ||
| <Link> | ||
| <SubSystem>Console</SubSystem> | ||
| <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
| <OptimizeReferences>true</OptimizeReferences> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
| <ItemGroup> | ||
| <ClCompile Include="1520.cpp" /> | ||
| </ItemGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
| <ImportGroup Label="ExtensionTargets"> | ||
| </ImportGroup> | ||
| </Project> |
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <ItemGroup> | ||
| <Filter Include="Source Files"> | ||
| <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
| <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
| </Filter> | ||
| <Filter Include="Header Files"> | ||
| <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
| <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | ||
| </Filter> | ||
| <Filter Include="Resource Files"> | ||
| <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
| <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
| </Filter> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClCompile Include="1520.cpp"> | ||
| <Filter>Resource Files</Filter> | ||
| </ClCompile> | ||
| </ItemGroup> | ||
| </Project> |
| @@ -0,0 +1,12 @@ | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\1520\debug\vc120.pdb | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\1520\debug\vc120.idb | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\1520\debug\1520.obj | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\debug\1520.ilk | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\debug\1520.exe | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\debug\1520.pdb | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\1520\debug\1520.tlog\cl.command.1.tlog | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\1520\debug\1520.tlog\cl.read.1.tlog | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\1520\debug\1520.tlog\cl.write.1.tlog | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\1520\debug\1520.tlog\link.command.1.tlog | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\1520\debug\1520.tlog\link.read.1.tlog | ||
| c:\users\ma yesheng\desktop\oj\sjtu oj\1520\1520\debug\1520.tlog\link.write.1.tlog |
| @@ -0,0 +1,13 @@ | ||
| Build started 2015/11/4 0:05:14. | ||
| 1>Project "C:\Users\Ma Yesheng\Desktop\OJ\SJTU OJ\1520\1520\1520.vcxproj" on node 2 (Build target(s)). | ||
| 1>ClCompile: | ||
| D:\Program Files\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt 1520.cpp | ||
| 1520.cpp | ||
| Link: | ||
| D:\Program Files\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\Ma Yesheng\Desktop\OJ\SJTU OJ\1520\Debug\1520.exe" /INCREMENTAL /NOLOGO opencv_ts300d.lib opencv_world300d.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\Ma Yesheng\Desktop\OJ\SJTU OJ\1520\Debug\1520.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\Ma Yesheng\Desktop\OJ\SJTU OJ\1520\Debug\1520.lib" /MACHINE:X86 Debug\1520.obj | ||
| 1520.vcxproj -> C:\Users\Ma Yesheng\Desktop\OJ\SJTU OJ\1520\Debug\1520.exe | ||
| 1>Done Building Project "C:\Users\Ma Yesheng\Desktop\OJ\SJTU OJ\1520\1520\1520.vcxproj" (Build target(s)). | ||
|
|
||
| Build succeeded. | ||
|
|
||
| Time Elapsed 00:00:00.71 |
| @@ -0,0 +1,2 @@ | ||
| #TargetFrameworkVersion=v4.0:PlatformToolSet=v120:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit | ||
| Debug|Win32|C:\Users\Ma Yesheng\Desktop\OJ\SJTU OJ\1520\| |