stringstream做的,20分,求大佬帮助
查看原帖
stringstream做的,20分,求大佬帮助
1333398
AaronDing1495楼主2025/1/21 10:33

#1-#15 TLE

#16-#18 AC

#19 WA

#20 AC

代码打了九十八行......跪求指点!

#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
char ch;
string st="";
int main()
{
  stringstream tempIO;
  string container;
  int deleter;
  while(cin>>ch,ch!='\n')
  {
    if(ch!='.'&&ch!='/'&&ch!='%')
    {
      tempIO<<ch;
      tempIO>>container;
      tempIO.clear();
      st.append(container);
      container="";
    }
    else if(ch=='.'||ch=='/')
    {
      reverse(st.begin(),st.end());
      tempIO<<st;
      tempIO>>deleter;
      tempIO.clear();
      tempIO<<deleter;
      tempIO>>st;
      tempIO.clear();
      tempIO<<ch;
      tempIO>>container;
      tempIO.clear();
      st.append(container);
      container="";
    }
    else
    {
      reverse(st.begin(),st.end());
      tempIO<<st;
      tempIO>>deleter;
      tempIO.clear();
      tempIO<<deleter;
      tempIO>>st;
      tempIO.clear();
      return cout<<st<<'%',0;
    }
  }
  int sbl=0;
  int pos=0;
  string sticker;
  double deleterf;
  for(int i=0; i<st.size(); i++)
    if(st[i]=='.')sbl=1,pos=i;
    else if(st[i]='/')sbl=2,pos=i;
  if(sbl=0)
  {
    reverse(st.begin(),st.end());
    return cout<<st,0;
  }
  if(sbl=1)
  {
    for(int i=st.size(); i>=pos+1; i--)
    {
      tempIO<<st[i];
      tempIO>>container;
      tempIO.clear();
      sticker.append(container);
    }
    st.erase(pos+1,st.size()-pos-1);
    st.append(sticker);
    tempIO<<st;
    tempIO>>deleterf;
    tempIO.clear();
    tempIO<<deleterf;
    tempIO>>st;
    tempIO.clear();
    sticker="";
    return cout<<st,0;
  }
  if(sbl=2)
  {
    for(int i=st.size(); i>=pos+1; i--)
    {
      tempIO<<st[i];
      tempIO>>container;
      tempIO.clear();
      sticker.append(container);
    }
    st.erase(pos+1,st.size()-pos-1);
    st.append(sticker);
    sticker="";
    return cout<<st,0;
  }
  return 0;
}

回复必关~

2025/1/21 10:33
加载中...