#17677: 給延平的同仁 c++ AC


089487 (089487)

學校 : 國立臺灣師範大學附屬高級中學
編號 : 82069
來源 : [220.130.10.185]
最後登入時間 :
2024-04-01 11:16:18
b532. 字串處理 -- 102學年度商業類程式設計競賽 | From: [111.71.123.100] | 發表日期 : 2019-05-04 16:46

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
string s;
char c;
long long int n,m;
cin>>t;
bool f;
for(int g=0;g<t;g++)
{
cin>>s;
string a,b;
f=true;
for(int i=0;i<s.length();i++)
{
if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='%') c=s[i],f=false;
else if(s[i]>='0'&&s[i]<='9')
{
if(f)a+=s[i];
else b+=s[i];
}
}
stringstream ss(a);ss>>n;
stringstream s2(b);s2>>m;
if(c=='+') cout<<n+m<<endl;
else if(c=='-') cout<<n-m<<endl;
else if(c=='*') cout<<n*m<<endl;
else if(c=='/') cout<<n/m<<endl;
else cout<<n%m<<endl;
}
}

 
#17681: Re:給延平的同仁 c++ AC


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
b532. 字串處理 -- 102學年度商業類程式設計競賽 | From: [114.42.215.64] | 發表日期 : 2019-05-04 17:27

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
string s;
char c;
long long int n,m;
cin>>t;
bool f;
for(int g=0;g<t;g++)
{
cin>>s;
string a,b;
f=true;
for(int i=0;i<s.length();i++)
{
if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='%') c=s[i],f=false;
else if(s[i]>='0'&&s[i]<='9')
{
if(f)a+=s[i];
else b+=s[i];
}
}
stringstream ss(a);ss>>n;
stringstream s2(b);s2>>m;
if(c=='+') cout<<n+m<<endl;
else if(c=='-') cout<<n-m<<endl;
else if(c=='*') cout<<n*m<<endl;
else if(c=='/') cout<<n/m<<endl;
else cout<<n%m<<endl;
}
}

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv){
cin.tie(0);
ios::sync_with_stdio(false);
string a;
int b,c,d,f;
cin>>c;
getline(cin,a);
while(c--){
b=0;
d=0;
getline(cin,a);
for(int e=0;e<a.size()+1;e++){
if(a[e]>='0'&&a[e]<='9')
d=d*10+int(a[e])-48;
else if(a[e]=='+'||a[e]=='-'||a[e]=='*'||a[e]=='/'||a[e]=='%'){
b=b+d;
d=0;
if(a[e]=='+')
f=1;
else if(a[e]=='-')
f=2;
else if(a[e]=='*')
f=3;
else if(a[e]=='/')
f=4;
else if(a[e]=='%')
f=5;
}
}
if(f==1)
cout<<b+d<<endl;
else if(f==2)
cout<<b-d<<endl;
else if(f==3)
cout<<b*d<<endl;
else if(f==4)
cout<<b/d<<endl;
else if(f==5)
cout<<b%d<<endl;
}
}


AC (2ms, 360KB)



 
#17866: Re:給延平的同仁 c++ AC


rexwu1104@gmail.com (黑雪公主 Black Lotus)

學校 : 新北市私立南山高級中學
編號 : 93041
來源 : [118.166.54.130]
最後登入時間 :
2022-06-06 20:48:09
b532. 字串處理 -- 102學年度商業類程式設計競賽 | From: [111.249.33.239] | 發表日期 : 2019-05-26 21:54

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
string s;
char c;
long long int n,m;
cin>>t;
bool f;
for(int g=0;g<t;g++)
{
cin>>s;
string a,b;
f=true;
for(int i=0;i<s.length();i++)
{
if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='%') c=s[i],f=false;
else if(s[i]>='0'&&s[i]<='9')
{
if(f)a+=s[i];
else b+=s[i];
}
}
stringstream ss(a);ss>>n;
stringstream s2(b);s2>>m;
if(c=='+') cout<<n+m<<endl;
else if(c=='-') cout<<n-m<<endl;
else if(c=='*') cout<<n*m<<endl;
else if(c=='/') cout<<n/m<<endl;
else cout<<n%m<<endl;
}
}

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv){
cin.tie(0);
ios::sync_with_stdio(false);
string a;
int b,c,d,f;
cin>>c;
getline(cin,a);
while(c--){
b=0;
d=0;
getline(cin,a);
for(int e=0;e<a.size()+1;e++){
if(a[e]>='0'&&a[e]<='9')
d=d*10+int(a[e])-48;
else if(a[e]=='+'||a[e]=='-'||a[e]=='*'||a[e]=='/'||a[e]=='%'){
b=b+d;
d=0;
if(a[e]=='+')
f=1;
else if(a[e]=='-')
f=2;
else if(a[e]=='*')
f=3;
else if(a[e]=='/')
f=4;
else if(a[e]=='%')
f=5;
}
}
if(f==1)
cout<<b+d<<endl;
else if(f==2)
cout<<b-d<<endl;
else if(f==3)
cout<<b*d<<endl;
else if(f==4)
cout<<b/d<<endl;
else if(f==5)
cout<<b%d<<endl;
}
}


AC (2ms, 360KB)



 

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a;
	while (cin >> a) {
    string b; long int one=0, two=0; int c=0, d, ans;
    for (int i=0;i<a;i++) {
      cin >> b;
      for (int m=0;m<b.size();m++) {
        if (b[m]>57) ;
        else if (b[m]=='+') {
          d='+';
          c=m;
          break;
        }
        else if (b[m]=='-') {
          d='-';
          c=m;
          break;
        }
        else if (b[m]=='*') {
          d='*';
          c=m;
          break;
        }
        else if (b[m]=='/') {
          d='/';
          c=m;
          break;
        }
        else if (b[m]=='%') {
          d='%';
          c=m;
          break;
        }
        else {
          one+=b[m]-48;
          one*=10;
        }
      }
      one/=10;
      for (int m=c+1;m<b.size();m++) {
        if (b[m]>57) ;
        else {
          two+=b[m]-48;
          two*=10;
        }
      }
      two/=10;
      if (d==43) ans=one+two;
      else if (d==45) ans=one-two;
      else if (d==42) ans=one*two;
      else if (d==47) ans=one/two;
      else  ans=one%two;
      cout << ans << endl;
      one=0; two=0;
    }
	}
}

AC (2ms, 344KB)


 
ZeroJudge Forum